Любимые вопросы на собеседовании
Все числа в JavasScript представлены
как числа с плавающией точкой двойной точности.
Каждое число представлено 64 битами.
Мантисса от 0 до 52 бита
Экспонента от 52 до 62
Знак храниться в 63 бите
http://2ality.com/2012/04/number-encoding.html
0.1 + 0.2 === 0.30000000000000004;
typeof 10 === "number";
typeof NaN === "number";
BigInt(1);const obj = {};
function fun (arg1) {
arg1.name = "Winderton"
}
fun(obj);
console.log(obj.name); // => WindertonМутация объекта
typeof {a: 1} === "object";
typeof [1, 2, 4] === "object"; // Use Array.isArray
typeof new Date() === "object";
typeof /regex/ === "object";
// Тоже объекты, не используйте этот синтакс!
typeof new Boolean(true) === "object";
typeof new Number(1) === "object";
typeof new String('abc') === "object";
Почти все — объект!
Array.prototype.sort = function (sorter) {
return []; // :D
};
[3, 5, 1, 9].sort(); // => []Благодаря прототипной модели некоторые ушлые библиотеки изменяли сам язык.
Теперь мы страдаем!
class Animal {
}
function ProtoAnimal () {
}
const dog = new Animal();
const cat = new ProtoAnimal();
dog.prototype = cat;Синтаксис классов в JS — это просто абстракция над прототипами.
В итоге глубокое наследование медленное и другие приключения Шурика.
db.connect(function (connection) {
connection.save(data, function(err) {
if (err) {
console.error(err);
}
else {
console.log("Ok!")
}
});
});Везде и от нее не спрятаться и не скрыться!
db.connect().then(function (connection) {
return connection.save(data);
}).then(function() {
console.log("Ok!");
}).catch(function (err) { // !!!
console.error(err);
});
Везде и от нее не спрятаться и не скрыться!
const connection = await db.connect();
try {
connection.save(data);
console.log("Ok!");
}
catch (err) {
console.error(err);
}
Везде и от нее не спрятаться и не скрыться!
asyncActionOne(callback1);
asyncActionTwo(callback2);
asyncActionThree(callback3);
// !==
await asyncActionOne();
await asyncActionTwo();
await asyncActionThree();
Везде и от нее не спрятаться и не скрыться!
На беке упаковал все в Docker и кайфуешь
😈
var fs = require("fs");
module.exports = {
// ...
};
import fs from "fs";
export default class Test {
// ...
}