Year | JavaScript | jScript | ES | ES Additions |
---|---|---|---|---|
96 | 1.0, 1.1 | 1.0 | 1 | |
97 | 1.2 | 3.0 | 1 | (1st Edition) |
98 | 1.3 | |||
99 | 5.0, 5.1 | 2 | (Editorial changes only) | |
00 | 1.5 | 5.5 | 3 | RegExp, Try/Catch, standardized the switch statement |
01 | 5.6 | |||
05 | 1.6 | |||
06 | 1.7 | 5.7 | ||
08 | 1.8 | |||
09 | 5 | strict mode, JSON support | ||
11 | 9.0 | 5.1 | (Editorial changes) | |
15 | 6 | Classes, modules | ||
16 | 7 | Exponential operator (**), Array.prototype.includes |
Declaring a variable after it has been used. Not the same as using a variable before it has been initialized. JS hoists declarations as if they were at the top of the code, but not initializations.
x = 5
console.log(x) // 5
console.log(y) // undefined
var y = 7
var x
It's an object so use curly braces. Key pairs key:value, keys in double quotes. May contain arrays (square brackets).
{"username":"John", "aliases":["JonJon", "The Anialator"]}
ES introduced Symbol.iterator. Any type that contains Symbol.iterator can be iterated. You can find out if a variable v has this property by using console.dir(v). The prototype for Array, Sets and Maps have this property but Objects don't.
const numArray = [3,7,9,4];
const len = numArray.length;
for (let i = 0; i < len; i++) {
console.log(numArray[i]);
}
const mySet = new Set([1,2,2,2,3]);
console.dir(mySet);
for (let val of mySet) {
console.log(var);
}
const anObject = {
name: "Bob",
age: "29",
friends: ['john', 'kim', 'peter'],
getName function() {
return this.name;
}
}
for (let key in anObject) {
console.log(key);
}
const myArray = [1,2,3,4,5];
const iterator = myArray[Symbol.iterator]();
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
The six lines calling iterator.next return an object
{value: 1, done: false}
{value: 2, done: false}
{value: 3, done: false}
{value: 4, done: false}
{value: 5, done: false}
{value: undefined, done: true}