Member-only story

Modern JavaScript For React Developers

Rabin Poudyal
3 min readMar 27, 2019

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…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Rabin Poudyal
Rabin Poudyal

Written by Rabin Poudyal

Software Engineer, Data Science Practitioner. Say "Hi!" via email: rabinpoudyal1995@gmail.com or visit my website https://rabinpoudyal.com.np

No responses yet

Write a response