AdsReg.com Magazine Logo
📌 Press Ctrl+D to bookmark this page.

Variables

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/004-Variables

 

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

 

Sample2: Use Variables with (var)

JavaScript/004-Variables/001-var

Sample3: Use Variables with (let)

JavaScript/004-Variables/002-let

Leave a Comment

Your email address will not be published. Required fields are marked *

AdsReg Magazine We would like to show you notifications for the latest news and updates. You can disable it when you want.
Dismiss
Allow Notifications