New way to declare variables
This post is a part of Starter to ES6
Instead of var we can use
- let: declare variable names
- const: declare constant variables that can not be changed, one time single assignment.
ES6: let, const
ES5 (old javascript): var
Unlike variables declared with var that are function scoped, variables declared with let or const are block scoped (they are only available in the block they are defined in).
Let us code our first ES6 code, inside your Development Environment in package.json file add the following lines.
“browserify”: {
“transform”: [“babelify”]
}
The above code will run browserify transform “babelify” each time there are changes in ES6 file it will compile ES6 to ES5, so package.json file will look like
in index.js file write:
let x = 15;
const tmp = ‘variable’;
console.log(x);
console.log(tmp);
Check the console of your browser