Created
August 23, 2021 12:43
-
-
Save obymanyando/629b71f750ed8268d8efc4f190f8edc9 to your computer and use it in GitHub Desktop.
Little JS Snippets
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
//Summing numbers | |
const sum = (a, b) => { | |
return a + b | |
} | |
console.log(sum(2, 5)) | |
// Summing Arbitatry Numbers | |
const sumArbitraryNums = () { | |
let sum = 0 | |
for (const num of arguments) { | |
sum += num | |
} | |
return sum | |
} | |
console.log(sumArbitraryNums(2, 3, 100, 5, 20, 7)) | |
// Reduce | |
const reduceArbitraryNums = (...args) => args.reduce((a, b) => a + b) | |
console.log(reduceArbitraryNums(2, 3, 100, 5, 20, 7)) | |
//Object | |
const person = { | |
firstName: 'Oby', | |
lastName: 'Manyando', | |
getPersonInfo1: function () { | |
console.log(this) | |
}, | |
getPersonInfo2: () => { | |
//Notice behaviour of ES6 with this keyword | |
console.log(this) | |
}, | |
} | |
person.getPersonInfo1() | |
person.getPersonInfo2() | |
const getPersonInfo = () => { | |
return `He is ${person.firstName} ${person.lastName}` | |
} | |
console.log(getPersonInfo()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment