The fundamental of Javascript
tips
When I develop with Javascript, I have a few things that are not certain. For my reference, I organize them here.
=== vs ==
=== operator compares a value with another value. It validates the type of value and the value together. So it's stricter than ==.
But the one thing that you should remember is the operator === can be used for string and number type only.
let vs var
Using let is more recommended than using var. It's stricter. In other words, it helps you to avoid causing an error.
A variable declared by let is limited to a block in which the variable is placed.
function a() {
let v = ‘test’;
console.log(v);
}
console.log(v); // This causes an error.
Primitive types
Javascript has boolean, number, string, undefined, object, function, and symbol as primitive types.
let isBool = false;
typeof isBool; // boolean
let age = 30;
typeof age; // number
let name = “woong”;
typeof name; // string
let icecreams = [“choco”, “vani”, “lemon”, “strawberry”];
typeof icecreams; // object
let isNull = null;
typeof isNull; // object
let fa = function() { console.log(“function”); }
typeof fa; // function
let isUndefined;
typeof isUndefined; // undefined