Skip to content

Hardest JavaScript questions that I could think of

License

Notifications You must be signed in to change notification settings

themithy/the-insane-javascript-interview

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Insane JavaScript interview

This is a compilation of hardest JavaScript questions that I could think of. The difficulty level is beyond the level of sanity and even skilled programmers should never be bothered with such language features. But if you are interested in the less-known parts of the spec - give it a try!

  1. What would be the result of the following expression ?
console.log(!'0' == '0') // ?
  1. What would be the result of running the following code ?
undefined = null // ?
  1. What would be the result of running the following code ?
var a = 1

{
  let a = a + 1
  console.log(a) // ?
}
  1. How to reliably check whether a variable is an object ?

  2. What would be the result of running the following code ?

function func() {
  console.log(Array.isArray(arguments)) // ?
}

func(1, 2)
  1. How to detect whether a function has been called as a constructor ?

  2. What would be the result of running the following two lines of code ?

var a = new One() // ?
var b = new Two() // ?

function One() {} 

class Two {}
  1. What would be the result of running the following code ?
var a = {}
var b = {}

Object.setPrototypeOf(a, b)
Object.setPrototypeOf(b, a)
  1. What would be the result of the following expression ?
typeof [] instanceof Array
  1. What would be the result of the following expression ?
1000 == 01750n
  1. What would be the result of the following expression ?
console.log(2**53 == 2**53 + 1) // ?
  1. What would be the result of running the following code ?
const obj = {}

obj[undefined] = 1
obj[false] = 2
obj[+0] = 3
obj[-0] = 4
obj['0'] = 5
obj[{}] = 6

console.log(Object.values(obj)) // ?
  1. What would be the result of running the following code ?
const Func = () => {}

const val = new Func() // ?
  1. What would be the result of running the following code ?
function Tree() {}

const tree = new Tree()

console.log(tree.constructor.prototype.__proto__.__proto__) // ?
  1. What would be the result of running the following code ?
const target = new Number(5)
const proxy = new Proxy(target, {})

console.log(proxy.toString()) // ?
  1. What is the difference between Object.preventExtensions, Object.seal and Object.freeze ?

  2. What would be the result of running the following code ?

function a() {
  const x = arguments[0]

  const b = () => {
    const y = arguments[0]
    console.log(y) // ?
  }

  b(2 * x)
}

a(10)
  1. What would be the result of running the following code ?
const key = Symbol('abc')

const obj = { [key]: 'def' }

console.log(JSON.stringify(obj)) // ?
  1. What would be the result of the following expression ?
false.__proto__
  1. What would be the result of the following expression ?
typeof /abc/
  1. What is the difference between Object.keys and Object.getOwnPropertyNames ?

  2. What would be the result of running the following code ?

function a() {}
const b = () => {}

a.__proto__ == b.__proto__ // ?
  1. What would be the result of running the following code ?
Promise.resolve()
  .then(() => Promise.resolve('abc'))
  .then((val) => {
    console.log(typeof val) // ?
  })
  1. What would be the result of the following expression ?
1 + - 0 || new 0
  1. What would be the result of running the following code ?
async function print(val) {
  console.log(val)
}

async function run() {
  [1, 2, 3].forEach(async (val) => {
    await print('A' + val)
    print('B' + val)
  })
}

run()
  1. What would be the result of the following expression ?
Symbol('1') + '2'
  1. What would be the result of running the following code ?
var a = b, b = 1

console.log('a: ' + a) // ?
console.log('b: ' + b) // ?
  1. What would be the result of running the following code ?
var prop = 1

delete prop // ?
  1. What would be the result of the following expression ?
null == false
  1. What would be the result of running the following code ?
const a = new Date()
const b = Object.assign(Object.create(Date.prototype), a)

a.toString() == b.toString() // ?
  1. What would be the result of running the following code ?
const obj = {}
const arr = []

obj[5] = true
arr[5] = true

obj['5'] // ?
arr['5'] // ?
  1. What would be the result of running the following code ?
const arr = [ 1, 2, 3 ]
arr[7.5] = true

arr.length = 0

Object.getOwnPropertyNames(arr) // ?
  1. What would be the result of running the following code ?
function func() {
  this.prop = 2
  return { prop: 4 }
}

func.prototype.prop = 6

const obj = new func()

obj.prop // ?
  1. What would be the result of running the following code ?
const arr = []
Object.setPrototypeOf(arr, Object.prototype)

arr instanceof Array // ?
  1. What would be the result of running the following code ?
[ 0, 2, 4 ].flatMap((x) => [ x, x + 1 ])
  1. What would be the result of the following expression ?
new Int8Array instanceof Array
  1. What would be the result of running the following code ?
let i = 0

for (; i < 10; i++) {
  setTimeout(() => console.log('i=' + i))
}
  1. What would be the result of running the following code ?
const obj = { a: true }

for (const v of obj) {
  console.log(v)
}
  1. What would be the result of running the following code ?
const arr = []
const it = arr[Symbol.iterator]()

it.next() // ?
  1. What would be the result of running the following code ?
const map = new Map()

map['a'] = true
map.set('b', true)

map.get('a') // ?
map['b'] // ?
  1. What would be the result of running the following code ?
const arr = [1, 2, 3]

for (const a of arr) {
  if (a <= 3) {
    arr.push(a + 3)
  }
  console.log(a)
}
  1. What would be the result of running the following code ?
const obj = {}

Object.defineProperty(obj, 'a', {})
Object.defineProperty(obj, 'b', { get: () => {} })
Object.defineProperty(obj, 'c', { set: () => {} })

Object.getOwnPropertyNames(obj) // ?
  1. What would be the result of the following expression ?
NaN ** 0
  1. What would be the result of the following expression ?
JSON.parse('{}').__proto__
  1. What would be the result of running the following code ?
function Func() {
  return new this.constructor()
}

new Func()
  1. What would be the result of the following expressions ?
// 1.
true + true // ?

// 2.
true + 1 // ?

// 3.
true + '1' // ?
  1. What is the difference between Function.prototype.call and Function.prototype.apply ?

  2. What is the purpose of function Reflect.construct ?

  3. What is the difference between Object.preventExtensions and Reflect.preventExtensions ?

Final one. Why are all those questions so difficult ?

About

Hardest JavaScript questions that I could think of

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published