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 someStringNum = "3.5"; | |
| +someStringNum + 2; // returns 5.5 | |
| +null // returns 0 |
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 someNum = 30; | |
| // Long | |
| someNum.toString(); // returns "30" | |
| 10.toString(); // returns "10" | |
| // Shorthand 👍🏽 | |
| `${someNum}`; // returns "30" | |
| `10` // returns "10" |
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 arrayOne = [1,2,3]; | |
| // Long way | |
| const newArrayOld = arrayOne.slice(); // returns [1,2,3] | |
| // Shorthand 👍🏽 | |
| const newArray = [...arrayOne]; // returns [1,2,3] |
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 arrayOne = [2, 4, 1]; | |
| let arrayTwo = [1, 3, 5]; | |
| //Long way | |
| arrayOne.concat(arr2); // returns [ 2, 4, 1, 1, 3, 5 ] | |
| // Shorthand 👍🏽 | |
| [...arr1, ...arr2]; // returns [ 2, 4, 1, 1, 3, 5 ] |
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 someArray = [1,3,2,1,2,3]; | |
| [...new Set(someArray)]; // returns [ 1, 3, 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 someString = "Dhanik"; | |
| // Long | |
| someString.charAt(0); //returns "D" | |
| // Shorthand | |
| someString[0]; //returns "D" |
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
| if(someCondition){ | |
| console.log("Hello World"); | |
| } | |
| // Same if condition in a single line. 👍🏽 | |
| if(someCondition) console.log("Hello World"); |
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
| if(someCondition !== undefined && someCondition !== null){ | |
| // handle whatever | |
| } |
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 objOne = { foo: "bar", x: 2 }; | |
| const objTwo = { foo: "bar", y: 5}; | |
| // Long way | |
| const copiedObj = Object.assign({},objOne); // Object { foo: "bar", x: 2 } | |
| const mergedObj = Object.assign(objOne,objTwo); //Object { foo: "bar", x: 2, y:5 } | |
| // Shorthand way 👍🏽 | |
| const copiedObj = {...objOne}; // Object { foo: "bar", x: 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 firstNum = 10; | |
| const secNum = 20; | |
| //Shorthand way 👍🏽 | |
| console.log(`Hi, this is how we should concatinate | |
| with a multiliine string`); | |
| //Hi, this is how we should concatinate | |
| //with a multiliine string | |
| //Shorthand way 👍🏽(Expression interpolation) |