I have compiled some basic JavaScript language questions so developers can test their knowledge, and also learn some nuances of the language from the detailed answers to each question.
The repository is open to contributions, whether new questions or even translations of answers into other languages.
- Assuming ECMAScript 6;
- Every snippet is run as a global code;
- The code is not running in strict mode.
('b'+'a'+ +'a'+'a').toLocaleLowerCase()
a) SyntaxError
b) 'baaa'
c) 'banana'
d) 'baa'
let num = '10'
num += num++
a) '1010'
b) NaN
c) '1011'
d) 21
(function () {
let num1 = 10
let num2 = 20
return sum()
function sum() {
return num1 + num2
}
})()
a) undefined
b) NaN
c) 30
d) ReferenceError
function Person (firstName, lastName) {
this.firstName = firstName
this.lastName = lastName
}
let person = Person('Guilherme', 'Moura')
console.log('log 1: ', person)
console.log('log 2: ', firstName, lastName)
a) log 1: Guilherme Moura | ReferenceError
b) log 1: undefined | log 2: Guilherme Moura
c) log 1: { firstName: 'Guilherme', lastName: 'Moura' } | log 2: Guilherme Moura
d) log 1: { firstName: 'Guilherme', lastName: 'Moura' } | ReferenceError
(3,5 - 3) * 2
a) 0.999999
b) 0,5
c) 1
d) 4
let card = {};
(['audi','bmw'].map(item => card[item] = undefined), card)
a) {}
b) { audi: undefined, bmw: undefined }
c) ['audi','bmw']
d) [{ audi: undefined }, { bmw: undefined }]
Object.prototype.toString.call([1, 2, 3, 4, 5])
a) '[object Array]'
b) '1,2,3,4,5'
c) undefined
d) '[object Object]'
let john = { name: 'John' }
let array = [john]
john = null
array[0].name
a) TypeError
b) null
c) 'John'
d) undefined
Copyright (c) Guilherme Moura