var, let and const will be discussed with their scope, use and hoisting.
var keyword
let keyword
const keyword
Scope:var variable are globally scoped or function scoped
var test=10; function testJS() { console.log(test); } testJS();//10
function testJS() { var test=10; } testJS(); console.log(test);//error: test is not defined
var test =10; var test =15; OR var test =10; test =15;
In js a variable(var) can be used before it has been declared.
test=5; console.log(test);//5 var test;
var test; console.log(test); //undefined test=10; console.log(test); //10Variables and constants declared with let or const are not hoisted
problem with var Variables , it's override block scope by function scope
var test=10; if(test>5) { var test=5; } console.log(test);//5
Scope:let is block scoped {}.
let test=10; if(test>5) { let test=5; } console.log(test);//10
let test=10; if(test>5) { test=5; } console.log(test);//5
let test=10; test=5;
let test=10; let test=5;//error: Identifier 'test' has already been declared
const test=10; if(test>5) { const test=5; console.log(test);//5 } console.log(test);//10
const test=10; test=5;//Uncaught TypeError: Assignment to constant variable.
const test=10; const test=5;//Uncaught SyntaxError: Identifier 'test' has already been declared
const test={'name':'JS'}; test.name='JS6'; console.log(test.name);//JS6
test=5; console.log(test); let test; //Uncaught ReferenceError: Cannot access 'test' before initialization