Showing posts with label ES6. Show all posts
Showing posts with label ES6. Show all posts

Thursday, August 31, 2017

Use of Export and Require


Export
  • The export statement is used when creating JavaScript modules to export functions, objects, or primitive values from the module so they can be used by other programs with the import statement
  • Along with export we also need require or import
Require

  •  Used to consume modules. It allows you to include modules into your programs. You can include built-in core Node.js modules, community-based modules (node_modules) and local modules

Difference between let and var



The difference is scoping. var is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block. Both are global if outside any block.
Also, variables declared with let are not accessible before they are declared in their enclosing block. As seen in the demo, this will throw a ReferenceError exception.
They are very similar when used like this outside a function block.
let me = 'go';  // globally scoped
var i = 'able'; // globally scoped
However, global variables defined with let will not be added as properties on the global windowobject like those defined with var.
console.log(window.me); // undefined
console.log(window.i); // 'able'

Friday, April 14, 2017

Template literals in ES6



Template literals are new features that helps working with strings and string templates.We wrap our text in  `backticks  `

Finally we have classes in ES6


Classes creation and usage in ES5 was a pain. In ES6 we have class keyword and we can create methods and constructor on this class.

Note:This feature would not make JavaScript an object oriented language .These are syntax sugar over functions (Prototype over inheritance language)

Charlies angles for declaring variables in ES6



All these days we were able to use only var for declaring variables. Now we have the charlies angles options for declaring variables . What I mean is we have three ways of declaring variables.

Previously we had only 2 scopes. function scope and global scope. global scope is assigned if we do not declare var

How to use destructuring assignment in ES6 ?




Destructuring assignments helps to reduce the no of lines of code. Its basically sugarcoating