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!
- What would be the result of the following expression ?
console.log(!'0' == '0') // ?
- What would be the result of running the following code ?
undefined = null // ?
- What would be the result of running the following code ?
var a = 1
{
let a = a + 1
console.log(a) // ?
}
-
How to reliably check whether a variable is an object ?
-
What would be the result of running the following code ?
function func() {
console.log(Array.isArray(arguments)) // ?
}
func(1, 2)
-
How to detect whether a function has been called as a constructor ?
-
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 {}
- What would be the result of running the following code ?
var a = {}
var b = {}
Object.setPrototypeOf(a, b)
Object.setPrototypeOf(b, a)
- What would be the result of the following expression ?
typeof [] instanceof Array
- What would be the result of the following expression ?
1000 == 01750n
- What would be the result of the following expression ?
console.log(2**53 == 2**53 + 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)) // ?
- What would be the result of running the following code ?
const Func = () => {}
const val = new Func() // ?
- What would be the result of running the following code ?
function Tree() {}
const tree = new Tree()
console.log(tree.constructor.prototype.__proto__.__proto__) // ?
- What would be the result of running the following code ?
const target = new Number(5)
const proxy = new Proxy(target, {})
console.log(proxy.toString()) // ?
-
What is the difference between
Object.preventExtensions
,Object.seal
andObject.freeze
? -
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)
- What would be the result of running the following code ?
const key = Symbol('abc')
const obj = { [key]: 'def' }
console.log(JSON.stringify(obj)) // ?
- What would be the result of the following expression ?
false.__proto__
- What would be the result of the following expression ?
typeof /abc/
-
What is the difference between
Object.keys
andObject.getOwnPropertyNames
? -
What would be the result of running the following code ?
function a() {}
const b = () => {}
a.__proto__ == b.__proto__ // ?
- What would be the result of running the following code ?
Promise.resolve()
.then(() => Promise.resolve('abc'))
.then((val) => {
console.log(typeof val) // ?
})
- What would be the result of the following expression ?
1 + - 0 || new 0
- 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()
- What would be the result of the following expression ?
Symbol('1') + '2'
- What would be the result of running the following code ?
var a = b, b = 1
console.log('a: ' + a) // ?
console.log('b: ' + b) // ?
- What would be the result of running the following code ?
var prop = 1
delete prop // ?
- What would be the result of the following expression ?
null == false
- 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() // ?
- What would be the result of running the following code ?
const obj = {}
const arr = []
obj[5] = true
arr[5] = true
obj['5'] // ?
arr['5'] // ?
- 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) // ?
- 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 // ?
- What would be the result of running the following code ?
const arr = []
Object.setPrototypeOf(arr, Object.prototype)
arr instanceof Array // ?
- What would be the result of running the following code ?
[ 0, 2, 4 ].flatMap((x) => [ x, x + 1 ])
- What would be the result of the following expression ?
new Int8Array instanceof Array
- What would be the result of running the following code ?
let i = 0
for (; i < 10; i++) {
setTimeout(() => console.log('i=' + i))
}
- What would be the result of running the following code ?
const obj = { a: true }
for (const v of obj) {
console.log(v)
}
- What would be the result of running the following code ?
const arr = []
const it = arr[Symbol.iterator]()
it.next() // ?
- 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'] // ?
- 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)
}
- 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) // ?
- What would be the result of the following expression ?
NaN ** 0
- What would be the result of the following expression ?
JSON.parse('{}').__proto__
- What would be the result of running the following code ?
function Func() {
return new this.constructor()
}
new Func()
- What would be the result of the following expressions ?
// 1.
true + true // ?
// 2.
true + 1 // ?
// 3.
true + '1' // ?
-
What is the difference between
Function.prototype.call
andFunction.prototype.apply
? -
What is the purpose of function
Reflect.construct
? -
What is the difference between
Object.preventExtensions
andReflect.preventExtensions
?
Final one. Why are all those questions so difficult ?