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 eats(fruit1, fruit2, fruit3) { | |
console.log('Baby eats :- ', fruit1 + ', ' + fruit2 + ' and ' + fruit3); | |
} | |
let fruits = ['apple', 'mango', 'banana']; | |
eats(...fruits); |
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
// * Spread Operator in JavaScript ES6 | |
function eats(fruit1, fruit2, fruit3) { | |
console.log('Baby eats :- ', fruit1 + ', ' + fruit2 + ' and ' + fruit3); | |
} | |
let fruits = ['apple', 'mango', 'banana']; | |
eats(fruits[0], fruits[1], fruits[2]); |
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
// * Default value to an object being passed as a parameter using ES6 syntax | |
function personAge(age, { firstName = 'Richard', lastName = 'Hendricks' } = {}) { | |
console.log(firstName + ' ' + lastName + ' is ' + age + ' years old'); | |
} |
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
// * Default value using ES6 syntax | |
function add(a, b = 2) { | |
console.log(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
function add(a, b) { | |
b = b ? b : 2; | |
console.log(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
function add(a, b) { | |
console.log(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 perimeterOfARectangle = (length, breadth) => 2 * (length + breadth); | |
console.log(perimeterOfARectangle(10, 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 perimeterOfACircle4 = radius => 2 * 3.14 * radius; | |
console.log(perimeterOfACircle4(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
let perimeterOfACircle3 = (radius) => { | |
const PI = 3.14; | |
return 2 * PI * radius; | |
} | |
console.log(perimeterOfACircle3(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
let perimeterOfACircle2 = function(radius) { | |
const PI = 3.14; | |
return 2 * PI * radius; | |
} | |
console.log(perimeterOfACircle2(10)); |