This file contains hidden or 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
// Example 1 | |
const order = [20.17, 18.67, 1.50, "cheese", "eggs", "milk", "bread"]; | |
const [total, subtotal, tax, ...items] = order; | |
console.log(total, subtotal, tax, items); // 20.17 18.67 1.5 ["cheese", "eggs", "milk", "bread"] | |
// Example 2 | |
function sum(...nums) { | |
let total = 0; | |
for(const num of nums) { | |
total += num; |
This file contains hidden or 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
// Example 1 | |
const books = ["Don Quixote", "The Hobbit", "Alice in Wonderland", "Tale of Two Cities"]; | |
console.log(...books); // Don Quixote The Hobbit Alice in Wonderland Tale of Two Cities | |
// Example 2 | |
const primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]; | |
console.log(...primes); // 2 3 5 7 11 13 17 19 23 29 | |
// Example 3 | |
const fruits = ["apples", "bananas", "pears"]; |
This file contains hidden or 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
Array.prototype.decimalfy = function() { | |
for (i = 0; i < this.length; i++) { | |
this[i] = this[i].toFixed(2); | |
} | |
}; | |
const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (const digit of digits) { | |
console.log(digit); |
This file contains hidden or 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 digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (const digit of digits) { | |
if (digit % 2 === 0) { | |
continue; | |
} | |
console.log(digit); | |
} | |
/** |
This file contains hidden or 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 digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (const digit of digits) { | |
console.log(digit); | |
} | |
/** | |
0 | |
1 | |
2 |
This file contains hidden or 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
Array.prototype.decimalfy = function() { | |
for (var i = 0; i < this.length; i++) { | |
this[i] = this[i].toFixed(2); | |
} | |
}; | |
var digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (var index in digits) { | |
console.log(digits[index]); |
This file contains hidden or 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
var digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (var index in digits) { | |
console.log(digits[index]); | |
} | |
/** | |
0 | |
1 | |
2 |
This file contains hidden or 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
var digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (var i = 0; i < digits.length; i++) { | |
console.log(digits[i]); | |
} | |
/** | |
0 | |
1 | |
2 |
This file contains hidden or 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 firstName = "John"; | |
const lastName = "Doe"; | |
const birth = 1980; | |
const death = 1990; | |
const person = { | |
firstName, | |
lastName, | |
age() { | |
return death - birth; |
This file contains hidden or 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 firstName = "John"; | |
const lastName = "Doe"; | |
const age = 10; | |
const person = { | |
firstName, | |
lastName, | |
age, | |
} |
NewerOlder