Homejavascript

javascript

Tricky and conceptual JS interview questions.

ID: CS546166-001
const a = {};
const b = { key: "b" };
const c = { key: "c" };

a[b] = 123;
a[c] = 456;

console.log(a[b]);
  • 123
  • 456
  • undefined
  • Error
ID: CS546181-002
let x = 10;
let y = (x++, x + 5);

console.log(x, y);
  • 11, 15
  • 10, 15
  • 11, 16
  • 10, 16
ID: CS546196-003
console.log(typeof NaN);
console.log(NaN === NaN);
  • number, true
  • NaN, false
  • number, false
  • undefined, false
ID: CS546212-004
let a = "5";
let b = 2;
let result = a - b + b;

console.log(result);
  • 5
  • "52"
  • "5"
  • NaN
ID: CS546227-005
let a = [1, 2, 3];
let b = a;
a = [4, 5, 6];

console.log(b);
  • [4, 5, 6]
  • [1, 2, 3]
  • undefined
  • Error
ID: CS546243-006
let a = 0;

if (a = 5) {
  console.log("True");
} else {
  console.log("False");
}
  • True
  • False
  • Error
  • undefined
ID: CS546258-007
function test() {
  var a = 5;
  return function () {
    console.log(a);
    var a = 10;
  };
}
test()();
  • 5
  • 10
  • undefined
  • ReferenceError