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 array1 = [1,2,3,4] | |
//Copying an array | |
let copyArray = [...array1] | |
copyArray.push(4) | |
console.log(array1) | |
console.log(copyArray) | |
/* | |
[ 1, 2, 3, 4 ] |
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
for(let a = 0, b = 0; a < 10 && b < 100; a++, b+=10) { | |
console.log(a, b) | |
} | |
/* | |
0 0 | |
1 10 | |
2 20 | |
3 30 | |
4 40 | |
5 50 |
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
for(let a = 0, b = 0; a < 10 && b < 100; console.log("Your counters are at:", ++a, b+=2)){} | |
/* | |
Your counters are at: 1 2 | |
Your counters are at: 2 4 | |
Your counters are at: 3 6 | |
Your counters are at: 4 8 | |
Your counters are at: 5 10 | |
Your counters are at: 6 12 | |
Your counters are at: 7 14 | |
Your counters are at: 8 16 |
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
function isItDone(a) { | |
console.log("fn called!") | |
return a < 10 | |
} | |
for(let a = 0; isItDone(a); a++) { | |
console.log(a) | |
} | |
/* | |
fn called! |
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 myMap { | |
uno: 1, | |
dos: 2, | |
tres: 3 | |
} | |
for(let key in myMap) { | |
console.log(key, "=", myMap[key]); | |
} | |
/* | |
uno = 1 |
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
for(let k in "Hello World!") { | |
console.log(k) | |
} | |
/* | |
0 | |
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
for(let char of "Hello World!") { | |
console.log(char) | |
} | |
/* | |
H | |
e | |
l | |
l | |
o | |
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 fs = require("fs") | |
async function read(fname) { | |
return new Promise( (resolve, reject) => { | |
fs.readFile(fname, (err, content) => { | |
if(err) return reject(err) | |
resolve(content.toString()) | |
}) | |
}) | |
} |
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 myArr = ["hello", "world"] | |
for([idx, value] of myArr.entries()) { | |
console.log(idx, '=', value) | |
} | |
/* | |
0 '=' 'hello' | |
1 '=' 'world' | |
*/ |
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 fs = require("fs") | |
async function read(fname) { | |
return new Promise( (resolve, reject) => { | |
fs.readFile(fname, (err, content) => { | |
if(err) return reject(err) | |
resolve(content.toString()) | |
}) | |
}) | |
} |