-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0. variables.js
More file actions
38 lines (29 loc) · 1.07 KB
/
0. variables.js
File metadata and controls
38 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Three ways to define variables in JavaScript ::
// 1. var
var name = "John"; // can be re-declared and updated
console.log(name);
// Not recommended for modern JavaScript due to its function scope and hoisting behavior
// 2. let
let age = 22; // can be updated but not re-declared in the same scope
console.log(age);
// Recommended for block scope variables, preventing issues with variable hoisting
// 3. const
const pi = 3.14; // cannot be updated or re-declared
console.log(pi);
// Recommended for constants, ensuring values remain unchanged throughout the code
console.log("---------------------------- ::");
// var (Can be updated) example :
var score = 10;
console.log("Initial Score: ", score);
var score = 27;
console.log("After re-declaration: ", score);
// let (Can be updated) example :
let playerLevel = 1;
console.log("Original level: ", playerLevel);
playerLevel = 3;
console.log("Updated level: ", playerLevel);
// const (cannot be updated) example :
const gameTitle = "Super Mario";
console.log("Game title: ", gameTitle);
//gameTitle = "Zelda";
//console.log("erorr");