Variables in ES6
ES6 include a new kinds of variables let and const.
Let
let nom = 'lucas';
return nom; // lucas
nom = 'thomas';
return nom; // thomas
function driverlicence(passed) {
if(passed) {
let name = 'lucas'; // let and const create a block scop
const age = 1995;
return '${name} can now drive, he was born in ${age}'; // lucas can now drive, he was born in 1995
}
return '${name} can now drive, he\'s was born in ${age}'; // Error !!!!
}
let i = 23;
for(let i = 0; i < 5; i++) {
return i; // 0,1,2,3,4
}
return i; // 23
- With es6 you can declares variables with two new terms let, const.
- One specific thing about
let
andconst
is the creation of block-scoped as you know in javascript a scoped is created only with functions but when you uselet
andconst
a scope is created in an if / else statements, a for loop etc.. as you can see in the example above.
Const
const age = 22;
return age; // 22
age = 25;
return age; // Error !!!
- A
const
variable works exactly the same thanlet
except that you can't change the value of aconst
variable.
Current errors
This is a list of the main errors that you can meet when you use class with ES6 syntax:
Note: I'm not a wizard there is maybe some issue that you notice above so fell free to open an issue in the github repo if you find a new error not mentioned above.