Member-only story
Modern JavaScript For React Developers

Difference between var, let and const.
var : It has a function wide scope. The scope of var is not defined by pair of curly braces so it has to be function and things like pair of braces of if statements does not define its scope. Even if we declare variable at the end of the function, we can use it at the beginning of function. This is because JS moves all variables to the top before executing the code. This is known as Hoisting.
let: It is essentially a block scoped version of var
. Its scope is limited to the block, statement or expression where it's defined, and all the contained inner blocks. Defining let
outside of any function - contrary to var
- does not create a global variable. Using modern JS we can completely replace var with let.
const: Defining varibale with let and const can be changed. Using const the variable cannot be reassigned. It does not provide immutability, just makes sure that the reference can’t be changed. const has block scope same as let.
Arrow functions
const myfunc = () => {console.log(‘my func’)}
Arrow functions have implicit return. you dont need to put return statements. Another example, when returning an object, remember to wrap the curly brackets in parentheses to…