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
// Input 5 | |
// output 11 | |
// (5 + 5) + 1 | |
function multiply(n){ | |
return 2 * n | |
} | |
function add(n) { | |
return n + 1 |
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
function greaterThan(n) { | |
return function(m) { | |
return m > n; | |
}; | |
} | |
var greaterThanTen = greaterThan(10); | |
var result1 = greaterThanTen(11) | |
console.log(result1) |
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
function greet(name) { | |
return `Hello, ${name}!`; | |
} | |
function shout(textFunction, name) { | |
const text = textFunction(name); | |
// toUpperCase is a built-in function of the | |
// String object which returns the value of | |
// the string converted to uppercase (capital letters) | |
const shoutText = text.toUpperCase(); |
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
function Animal() { | |
this.walk = function() { | |
console.log("I'm walking") | |
} | |
this.legs = function() { | |
console.log("I have 4 legs") | |
} | |
} |
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
let livingThing = { | |
doesLiveInfinitely() { | |
console.log("I do not live infinitely.") | |
} | |
} | |
let animal = { | |
eats: true, | |
walk() { | |
console.log("Animal walks"); |
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
class Animal { | |
walk() { | |
console.log("This animal walks") | |
} | |
legs() { | |
console.log("This animal has 4 legs") | |
} | |
} // All the common functionalities | |
// are represented in the class named Animal |
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
// // SPORTS is a class | |
// // cricket is an object (or an instance of this class) | |
// // tennis is an object (or an instance of this class) | |
// function Sports(name, totalPlayers) { | |
// this.game = name; | |
// this.totalP = totalPlayers; | |
// this.printTotalPlayers = function() { | |
// console.log(this.totalP); | |
// } |
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 dog = { | |
// name: 'Rex', | |
// age: 2, | |
// color: "brown", | |
// } | |
function Dog(name, breed, color) { | |
this.name = name; | |
// this keyword refers to the current object | |
// this is the object that is created when the |
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 name = 'Rex'; | |
const age = 2; | |
const color = "brown"; | |
function description() { | |
console.log( | |
`This is ${name}, he is ${age} years old and his color is ${color}` | |
) | |
} |
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
function Dog() { | |
const name = "Buzo"; | |
const age = 3; | |
const color = "black"; | |
const sound = "woof"; | |
function bark() { | |
console.log(sound); | |
} |