4 Ways to Declare a JavaScript Variable:
- Using var
- Using let
- Using const
- Using nothing
What are Variables?
Variables are containers for storing data. Like text / Numbers / Dates / Colors and more…
JavaScript let/var
Sample:
let x = "Bill Gates"; let x = 2000; // SyntaxError: 'x' has already been declared
var x = "Bill Gates"; var x = 2000; // No Error
{ let x = 777; } // x can NOT be used here
{ var x = 2; } // x CAN be used here
var x = 10; // Here x is 10 { var x = 2; // Here x is 2 } // Here x is 2