Давайте рассмотрим примеры ниже:
Q1: Почему здесь вывод 0
?Что это значит?
var a = 7;
console.log(a.constructor()); // prints 0 (Why?)
Q2: Когда typeof a
и typeof 7
оба числа, почему a.constructor()
работает, тогда как 7.constructor()
нет?
var a = 7;
var bool = typeof a === typeof 7;
console.log(a.constructor()); // 0
console.log((++a).constructor()); // 0
console.log(7.constructor()); // SyntaxError: Invalid or unexpected token
console.log(++a.constructor()); // ReferenceError: Invalid left-hand side expression in prefix operation