Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete operator example #6

Merged
merged 3 commits into from
Sep 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions JavaScript/7-delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const org = 'HowProgrammingWorks';

// delete org; // Raises SyntaxError in strict mode

const country = {
name: 'Chile',
ruler: 'Augusto Pinochet',
born: 1915,
alive: false
};

delete country.ruler;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✯ 👍 ☭

console.dir({ country });

delete country.born;
delete country.population;
console.dir({ country });

const currencies = ['BTC', 'EUR', 'UAH', 'USD'];

console.log('currencies[1]:', currencies[1], 1 in currencies);
console.log('currencies[2]:', currencies[2], 2 in currencies);

delete currencies[1];
currencies[2] = undefined;
console.dir({ currencies });

console.log('currencies[1]:', currencies[1], 1 in currencies);
console.log('currencies[2]:', currencies[2], 2 in currencies);