I am giving the second lecture to this books, You don’t know JS by Kyle Simpson.
That’s why I am reading for the second time the You Don’t Know JS books.
They are truly awesome, the author explains concepts super clearly and with examples.
I feel like I would get much more value if after reading them I do a small post as a reminder of the subjects that I believe are important.
And hopefully, you will find it useful too.
In case you want to check the series, you can read it for free on GitHub.
JS: Up and Going
Executing a program
When you write a statement like a = b * 2, the computer doesn’t understand it per se.
The way the computer understand this information is either using an interpreter or a compiler to translate the code to commands a computer can understand.
In some computer languages, the translation of code is typically line by line from top to bottom, which is called interpreting the code.
Other languages compiled the code ahead of time so the program runs later.
Values & Types
- Null and Undefined
- Symbol (new ES6)
You can use typeof to examine a value and check what type it is.
var a = 2;
typeof a “number”
When using typeof, it doesn’t ask for the type of the value a is, but rather for the type of value currently in a.
It would try to convert one of them to the equivalent value of the other to be able to compare them.
There are two different types of coercions, explicit and implicit.
Explicit coercion is the conversion form of one type to the other in a simple way, like :
var a = “20”;
typeof a; “string”
var b = Number(a);
typeof b; “number”
Implicit coercion is when the type of conversion can happen as more of a non obvius side effect of some other operation.
var a = “22”;
typeof a; “string”
var b = a *2;
typeof b: “number”
Thuthy & Falsy
- “” (empty string”
- 0, -0, NaN (invalid number)
- null, undefined
Any other value that is not in the falsy list it would be truthy.
There are four equality operators: ==, ===, != and !==.
The difference between == and === is that == check for value equality and === check for both value and type equality.
When to use == or ===:
- If either value in a comparison could be the true or false value, avoid == and use ===.
- If either value in a comparion could be of these especific values (0, “”, or [ ]), avoid == and use ===.
- In all other cases, use ==.
Next one on the list, Scope & Closures.