Let's look at the examples below:
Q1: Why is the output 0
here? What does it mean?
var a = 7;
console.log(a.constructor()); // prints 0 (Why?)
Q2: When typeof a
and typeof 7
both are number, why a.constructor()
runs whereas 7.constructor()
doesn't?
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