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 someArray = [1, 2, 3, [11, 22, 33]]; | |
console.log("array object:", someArray); | |
console.log("array to string:", someArray.toString()); | |
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 a; // is undefined | |
var b = "name"; // is defined | |
console.log("A:" + a); // prints undefined | |
console.log("B:" + b); // prints "name" | |
console.log("C" + c); // ReferenceError not defined | |
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
// this is a single line comment | |
var a = 5; // single line comment after legit code | |
var a = 5; // single line comment, commenting out the code | |
/* this is a multi-line comment | |
this is a multi-line comment | |
*/ | |
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 str = "I am a string variable that is declared and defined"; | |
console.log("I am a string"); // I am a string to console | |
console.log(str); // I am a string variable that is declared and defined | |
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
// order of precedence are the rules for the order in which value gets evaluated | |
console.log("1 * 2 + 3 * 2 =", 1 * 2 + 3 * 2); | |
console.log("1 * 2 + 3 * 2 * 5 =", 1 * 2 + 3 * 2 *5); | |
console.log("5 +1 * 2 + 3 * 2 * 5 =", 5 +1 * 2 + 3 * 2 * 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
// relational operators compare greater than, less than, or equal to | |
var a = 10; | |
var b = 5; | |
// a is greater than b | |
console.log("a is greater than b:", a > b); | |
// b is not greater than a | |
console.log("b is greater than a:", b > a); |
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
// arithmetic operators are your standard math operators | |
// we have addition + , subtraction - , multiplication * , division /, modulo/remainder %, | |
var a = 10; | |
var b = 5; | |
var c = 22; | |
// addition + | |
console.log("a + b =", a + b); |
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
// strict equality comparison operator is the triple equals ( === ) | |
// this checks for exact equality in value and type | |
var a = 4; | |
var b = 4; | |
var c = "4"; | |
// both a and b are numbers | |
console.log("a === b is:", a === b); |
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
// = the equal sign is the assignment operator; | |
var a = 10; // number ten is assigned to variable a; | |
var b = 20; | |
var c = 12; | |
a = c; // a is 12 | |
console.log("a: " + a); | |
a = c = b; // a is 20, c is 20, b is 20 | |
console.log("a: " + a); | |
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
// Promise.all is good for executing many promises at once | |
Promise.all([ | |
promise1, | |
promise2 | |
]); | |
// Promise.resolve is good for wrapping synchronous code | |
Promise.resolve().then(function () { | |
if (somethingIsNotRight()) { | |
throw new Error("I will be rejected asynchronously!"); |