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
// rest param example | |
var multipleInputs = function (value, ...restParamValues ) { | |
restParamValues.forEach( function(paramVal){ | |
// do something with paramVal | |
}); | |
} |
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
// without default params | |
var myFunc = function (value, options){ | |
var value = value || 0; | |
var options = options || {}; | |
// do some stuff | |
} | |
// with default params | |
var myFunWithDefaultParam = function (value = 0, options = {}){ | |
// do some stuff |
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 person1 = 'Bob'; | |
const person2 = 'Fred'; | |
//using typical string concatenation | |
let oldConcatStr = 'We know that ' + person1 + ' is friends with ' + person2; | |
//using template strings | |
let newConcatStr = `We know that ${person} is friends with ${person2}` |
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
var multiplyAndPrint = (num1, num2) => { | |
let result = num1*num2; | |
return result; | |
} | |
// no brackets or return is required if function has just one line | |
var square = num => return num*num; |
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
class Person { | |
constructor(name = '', age = 0) { | |
this.name = name; | |
this.age = age; | |
} | |
getName() { | |
return this.name; | |
} | |
} |
NewerOlder