Quick references for fundamental things in JavaScript.
- Using
//for 1 line comment,/* */for multi-line comment.
- End of each command by
;.
- Variables and function name are case sensitive.
- Variables / functions should be named in the form of
nameOfVariable. - Naming a constant:
const FAV_PET = 'Cat';. UpperCamelCaseshould be used by convention for ES6 class names.
- Using
\\for special characters, for example,\\"for a"inside a"".
''can be used inside a""and vice versa.
Open the browser (I use Chrome), press
F12 to open the Inspect window, then choose tab Console. Now, you can practice on this console window, for example, try with 1+1 and press Ent.- "ES" = "ECMAScript" ~ "Javascript".
- Most of browsers use ES6 but not all.
- ES6 = ES2015
- New features: Arrow functions, Classes, Modules, Promises, Generators,
letandconst.
Difference between
var, let and constvar is "function" scope whereas log and const are "block" scope.- You don't need to use try/catch in every async/await. You only need to do it at the top level.
- Timeout Async
- Sync: tuần tự, lệnh này xong mới đến lệnh khác.
- Async: không đồng bộ, 1 command có thể execute trong khi thằng khác đang chạy → function chạy in background while program tiếp tục chạy những dòng khác!
- Why wee need asynchronous → js is single thread → perform long network requests without blocking the main thread. ← ref
- Comparison Operators:
<,==,===(strict equality),>,>=,<=,!=,!==(strict inequality). - Difference between
==and===:3=='3'(true),3==='3'(false). - Difference between
!=and!==:3!='3'(false),3!=='3'(true).
- Logical operators:
&&,||,!.
- Short-circuit evaluation:
let a = b || 'Thi';(ifbisn't defined yet,atakes value'Thi')
- Ternary Operator:
isNightTime ? console.log('Yes!') : console.log('No!');. We can use multiple nested ternary.
You can remove
break; to apply the same result for multiple cases.Check more statements.
Nested? 👉 Read these clear examples on MDN.
Older ways (ES5),
Rest parameter (ES6)
Spread Operator (ES6)
Check more methods.
Special characters:
\\' (single quote), \\" (double quote), \\\\(backslash), \\n (newline), \\r (carriage return), \\t (tab), \\b (word boundary), \\f (form feed).Check more methods.
We can use object for lookups instead of using
if..else or switchWe can create a nested object inside an object.
Prevent object mutation,
Extract values from object,
Assign variable from object,
Assign Variables from Nested Objects,
Assign Variables from Arrays,
Assignment with the Rest Parameter to Reassign Array Elements,
Pass an Object as a Function's Parameters,
JavaScript Object Notation or JSON is a related data interchange format used to store data,
To access
"CD": ourMusic[0].formats[0].- freeCodeCamp -- JavaScript Algorithms and Data Structures Certification (300 hours).
- w3schools -- JavaScript Tutorial.