👉 Note: Reading: You Don't Know JS Yet 1 - Get Started
// Instead of
var car = new Object();
var.color = 'red';
// We use
var car = { color: 'red' };
// Instead of
var arr = new Array(1, 2, 3)
// We use
var arr = [1, 2, 3]
// The ternary notation
// Instead of
var direction;
if (x < 1) direction = 1;
else direction = -1;
// We use
var direction = x < 1 ? 1 : -1;
// Instead of
var myApp = function(){
var name = 'Thi';
function getInfo(){
// [...]
}
}();
// We use
(function(){
var name = 'Thi';
function getInfo(){
// [...]
}
})()
var myApp = function(){
var name = 'Thi';
return getInfo(){
// [...]
}
}();
// Then
myApp.getInfo();