This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//how we can use var | |
if(true) { | |
var t = 9; | |
} | |
console.log(t) //prints 9 | |
//how we use let | |
let t1 = 9; | |
if(true) { | |
let t1 = 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(true) { | |
v = 9; | |
} | |
var v; | |
console.log(v) //prints 9 | |
if(true) { | |
v = 9; | |
} | |
let v; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nums = [10, 20, 30] | |
nums.push(40) | |
console.log(nums) //prints [10, 20, 30, 40] | |
const obj = { | |
age: 27, | |
} | |
obj.age = 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//tradional way | |
function fn(a, b) { | |
return a + b; | |
} | |
//using fat arrow style | |
var fn = (a, b) => a + b; | |
var fn = (a, b) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let name = "Gagan" | |
let age = 20 | |
let obj = { | |
name, //shorthand for name: name, | |
age, | |
} | |
console.log(obj.name) //prints "Gagan" | |
console.log(obj.age) //prints 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nums = [1, 2, 3] | |
let [a, b] = nums | |
console.log(a) //prints 1 | |
console.log(b) //prints 2 | |
let nums = [1, 2, 3] | |
let [a, ,c] = nums |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//In arrays | |
let nums = [1, 2, 3, 4, 5] | |
let [a, ...b] = nums | |
console.log(a) //prints 1 | |
console.log(b) //prints [2, 3, 4, 5] | |
let nums = [1, 2, 3, 4, 5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nums = [1, 2, 3, 4, 5] | |
console.log(Math.max(...nums)) //prints 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nums = [1, 2, 3, 4, 5] | |
for(let num of nums) { | |
console.log(num) | |
} | |
//prints 1 2 3 4 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let ss = "hey | |
this is not correct"; //error | |
let ss = `hey | |
i can write like this!` | |
//prints | |
//"hey | |
//i can write like this!" |
OlderNewer