PROGRAMMING

  minte9
learningjourney




S R Q

Let

To create a variable in JavaScript, use the let keyword.
 
/**
 * To create a variable in JavaScript, use the let keyword
 */

let name;
let message = "Hello World";

console.log(name); // undefined
console.log(message); // Hello World

let a = 1, b = 2; // not recommended

Var

Variables, declared with var are visible through blocks.
 
/**
 * In older scripts you find var keyword
 * Var has no block scope, not used in modern scripts
 */

{
    var a = 1; // global
    let b = 2;
}

console.log(a); // 1
console.log(b); // ReferenceError: b is not defined

Const

To declare a constant, we use const instead of let.
 
/**
 * To declare a constant, we use const instead of let
 * Constants are named using capital letters and underscores
 */
 
const COLOR_BLUE = "#00F";
const COLOR_ORANGE = "#FF7F00";

let color = COLOR_ORANGE;
console.log(color); // #FF7F00

Questions    
Last update: 60 days ago
Fundamentals, Data Types