Вопросы по JavaScript. Версия 1
Каким будет вывод?
Вопрос № 1
function sayHi() {
console.log(name)
console.log(age)
var name = "John"
let age = 30
}
sayHi()
- A:
John
иundefined
- B:
John
иError
- C:
Error
- D:
undefined
иError
Ответ
Вопрос № 2
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1)
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1)
}
- A:
0 1 2
и0 1 2
- B:
0 1 2
и3 3 3
- C:
3 3 3
и0 1 2
- D:
3 3 3
и3 3 3
Ответ
Вопрос № 3
const shape = {
radius: 10,
diameter() {
return this.radius * 2
},
perimeter: () => 2 * Math.PI * this.radius
}
console.log(shape.diameter())
console.log(shape.perimeter())
- A:
20
и62.83185307179586
- B:
20
иNaN
- C:
20
и63
- D:
NaN
и63
Ответ
Вопрос № 4
console.log(+true)
console.log(!"John")
- A:
1
иfalse
- B:
0
иtrue
- C:
false
иNaN
- D:
false
иfalse
Ответ
Вопрос № 5
let c = { greeting: "Hey!" }
let d
d = c
c.greeting = "Hello!"
console.log(d.greeting)
- A:
Hello!
- B:
Hey!
- C:
undefined
- D:
Error
Ответ
Вопрос № 6
let a = 3
let b = new Number(3)
let c = 3
console.log(a == b)
console.log(a === b)
console.log(b === c)
- A:
true false true
- B:
false false true
- C:
true false false
- D:
false true true
Ответ
Вопрос № 7
class Chameleon {
static colorChange(newColor) {
this.newColor = newColor
return this.newColor
}
constructor({ newColor = "green" } = {}) {
this.newColor = newColor
}
}
const freddie = new Chameleon({ newColor: "pink" })
freddie.colorChange("orange")
- A:
orange
- B:
pink
- C:
green
- D:
Error
Ответ
Вопрос № 8
// обратите внимание: код выполняется в нестрогом режиме
let greeting
greetign = {} // опечатка!
console.log(greetign)
- A:
{}
- B:
Error
- C:
undefined
- D:
""
Ответ
Вопрос № 9
function bark() {
console.log("Woof!")
}
bark.animal = "dog"
console.log(bark.animal)
- A:
dog
- B:
Error
- C:
undefined
- D:
""
Ответ
Вопрос № 10
function Person(firstName, lastName) {
this.firstName = firstName
this.lastName = lastName
}
const person = new Person("John", "Smith")
Person.getFullName = function () {
return `${this.firstName} ${this.lastName}`
}
console.log(person.getFullName())
- A:
Error
- B:
""
- C:
John Smith
- D:
undefined undefined
Ответ
Вопрос № 11
function Person(firstName, lastName) {
this.firstName = firstName
this.lastName = lastName
}
const john = new Person("John", "Smith")
const jane = Person("Jane", "Air")
console.log(john)
console.log(jane)
- A:
Person {firstName: "John", lastName: "Smith"}
иundefined
- B:
Person {firstName: "John", lastName: "Smith"}
иPerson {firstName: "Jane", lastName: "Air"}
- C:
Person {firstName: "John", lastName: "Smith"}
и{}
- D:
Person {firstName: "Smith", lastName: "Smith"}
иError
Ответ
Вопрос № 12
function sum(a, b) {
return a + b
}
console.log(sum(1, "2"))
- A:
NaN
- B:
Error
- C:
"12"
- D:
3
Ответ
Вопрос № 13
let number = 0
console.log(number++)
console.log(++number)
console.log(number)
- A:
1 1 2
- B:
1 2 2
- C:
0 2 2
- D:
0 1 2
Ответ
Вопрос № 14
function getPersonInfo(one, two, three) {
console.log(one)
console.log(two)
console.log(three)
}
const person = "John"
const age = 30
getPersonInfo`${person} is ${age} years old`
- A:
John 30 ["", " is ", " years old"]
- B:
["", " is ", " years old"] John 30
- C:
John ["", " is ", " years old"] 30
- D:
undefined
Ответ
Вопрос № 15
function checkAge(data) {
if (data === { age: 18 }) {
console.log("Ты взрослый!")
} else if (data == { age: 18 }) {
console.log("Ты по-прежнему взрослый.")
} else {
console.log("Хм... У тебя что, нет возраста?")
}
}
checkAge({ age: 18 })
- A:
"Ты взрослый!"
- B:
"Ты по-прежнему взрослый."
- C:
"Хм... У тебя что, нет возраста?"
- D:
undefined
Ответ
Вопрос № 16
function getAge(...args) {
console.log(typeof args)
}
getAge(30)
- A:
number
- B:
array
- C:
object
- D:
NaN
Ответ
Вопрос № 17
function getAge() {
"use strict"
age = 30
console.log(age)
}
getAge()
- A:
30
- B:
undefined
- C:
Error
- D:
NaN
Ответ
Вопрос № 18
const sum = eval("10*10+5")
console.log(sum)
- A:
105
- B:
"105"
- C:
Error
- D:
"10*10+5"
Ответ
Вопрос № 19
var num = 8
var num = 10
console.log(num)
- A:
8
- B:
10
- C:
undefined
- D:
Error
Ответ
Вопрос № 20
const obj = { 1: "a", 2: "b", 3: "c" }
const set = new Set([1, 2, 3, 4, 5])
console.log(obj.hasOwnProperty("1"))
console.log(obj.hasOwnProperty(1))
console.log(set.has("1"))
console.log(set.has(1))
- A:
false true false true
- B:
false true true true
- C:
true true false true
- D:
true true true true
Ответ
Вопрос № 21
const obj = { a: "one", b: "two", a: "three" }
console.log(obj)
- A:
{ a: "one", b: "two" }
- B:
{ b: "two", a: "three" }
- C:
{ a: "three", b: "two" }
- D:
Error
Ответ
Вопрос № 22
for (let i = 1; i < 5; i++) {
if (i === 3) continue
console.log(i)
}
- A:
1 2
- B:
1 2 3
- C:
1 2 4
- D:
1 3 4
Ответ
Вопрос № 23
String.prototype.giveMePizza = () => {
return "Give me pizza!"
}
const name = "John"
console.log(name.giveMePizza())
- A:
"Give me pizza!"
- B:
Error
- C:
""
- D:
undefined
Ответ
Вопрос № 24
const a = {}
const b = { key: "b" }
const c = { key: "c" }
a[b] = 123
a[c] = 456
console.log(a[b])
- A:
123
- B:
456
- C:
undefined
- D:
Error
Ответ
Вопрос № 25
const foo = () => console.log("first")
const bar = () => setTimeout(() => console.log("second"))
const baz = () => console.log("third")
bar()
foo()
baz()
- A:
first second third
- B:
first third second
- C:
second first third
- D:
second third first
Ответ
Вопрос № 26
<div onclick="console.log('div')">
<p onclick="console.log('p')">
Нажми меня!
</p>
</div>
- A:
p div
- B:
div p
- C:
p
- D:
div
Ответ
Вопрос № 27
const person = { name: "John" }
function sayHi(age) {
console.log(`${this.name} is ${age}`)
}
sayHi.call(person, 30)
sayHi.bind(person, 30)
- A:
undefined is 30
иJohn is 30
- B:
function
иfunction
- C:
John is 30
иJohn is 30
- D:
John is 30
иfunction
Ответ
Вопрос № 28
function sayHi() {
return (() => 0)()
}
console.log(typeof sayHi())
- A:
object
- B:
number
- C:
function
- D:
undefined
Ответ
Вопрос № 29
console.log(typeof typeof 1)
- A:
number
- B:
string
- C:
object
- D:
undefined
Ответ
Вопрос № 30
const numbers = [1, 2, 3]
numbers[10] = 11
console.log(numbers)
- A:
[1, 2, 3, 7 x null, 11]
- B:
[1, 2, 3, 11]
- C:
[1, 2, 3, 7 x empty, 11]
- D:
Error
Ответ
Вопрос № 31
(() => {
let x, y
try {
throw new Error()
} catch (x) {
(x = 1), (y = 2)
console.log(x)
}
console.log(x)
console.log(y)
})()
- A:
1 undefined 2
- B:
undefined undefined undefined
- C:
1 1 2
- D:
1 undefined undefined
Ответ
Вопрос № 32
const result =
[[0, 1], [2, 3]].reduce(
(acc, cur) => {
return acc.concat(cur)
},
[1, 2]
)
console.log(result)
- A:
[0, 1, 2, 3, 1, 2]
- B:
[6, 1, 2]
- C:
[1, 2, 0, 1, 2, 3]
- D:
[1, 2, 6]
Ответ
Вопрос № 33
console.log(!!null)
console.log(!!"")
console.log(!!1)
- A:
false true false
- B:
false false true
- C:
false true true
- D:
true true false
Ответ
Вопрос № 34
console.log([..."John"])
- A:
["J", "o", "h", "n"]
- B:
["John"]
- C:
[[], "John"]
- D:
[["J", "o", "h", "n"]]
Ответ
Вопрос № 35
function* generator(i) {
yield i
yield i * 2
}
const gen = generator(10)
console.log(gen.next().value)
console.log(gen.next().value)
- A:
[0, 10]
и[10, 20]
- B:
20
и20
- C:
10
и20
- D:
0, 10
и10, 20
Ответ
Вопрос № 36
const firstPromise = new Promise((res, rej) => {
setTimeout(res, 500, "one")
})
const secondPromise = new Promise((res, rej) => {
setTimeout(res, 100, "two")
})
Promise.race([firstPromise, secondPromise]).then(res => console.log(res))
- A:
one
- B:
two
- C:
two one
- D:
one two
Ответ
Вопрос № 37
let person = { name: "John" }
const members = [person]
person = null
console.log(members)
- A:
null
- B:
[null]
- C:
[{}]
- D:
[{ name: "John" }]
Ответ
Вопрос № 38
const person = {
name: "John",
age: 30
}
for (const item in person) {
console.log(item)
}
- A:
{ name: "John" }
и{ age: 30 }
- B:
name
иage
- C:
John
и30
- D:
["name", "John"]
и["age", 30]
Ответ
Вопрос № 39
console.log(3 + 4 + "5")
- A:
"345"
- B:
"75"
- C:
12
- D:
"12"
Ответ
Вопрос № 40
const num = parseInt("7*6", 10)
console.log(num)
- A:
42
- B:
"42"
- C:
7
- D:
NaN
Ответ
Вопрос № 41
const result =
[1, 2, 3].map(num => {
if (typeof num === "number") return
return num * 2
})
console.log(result)
- A:
[]
- B:
[null, null, null]
- C:
[undefined, undefined, undefined]
- D:
[ 3 x empty ]
Ответ
Вопрос № 42
function greeting() {
throw "Всем привет!"
}
function sayHi() {
try {
const data = greeting()
console.log("Работает!", data)
} catch (error) {
console.log("Ошибка: ", error)
}
}
sayHi()
- A:
Работает! Всем привет!
- B:
Ошибка: undefined
- C:
Error
- D:
Ошибка: Всем привет!
Ответ
Вопрос № 43
function Car() {
this.make = "Lamborghini"
return { make: "Maserati" }
}
const myCar = new Car()
console.log(myCar.make)
- A:
Lamborghini
- B:
Maserati
- C:
Error
- D:
undefined
Ответ
Вопрос № 44
(() => {
let x = (y = 10)
})()
console.log(typeof x)
console.log(typeof y)
- A:
undefined
иnumber
- B:
number
иnumber
- C:
object
иnumber
- D:
number
иundefined
Ответ
Вопрос № 45
class Dog {
constructor(name) {
this.name = name
}
}
Dog.prototype.bark = function() {
console.log(`Woof I am ${this.name}`)
}
const pet = new Dog("Rex")
pet.bark()
delete Dog.prototype.bark
pet.bark()
- A:
"Woof I am Rex"
и""
- B:
"Woof I am Rex"
и"Woof I am Rex"
- C:
"Woof I am Rex"
иundefined
- D:
"Woof I am Rex"
иError
Ответ
Вопрос № 46
const set = new Set([1, 1, 2, 3, 4])
console.log(set)
- A:
[1, 1, 2, 3, 4]
- B:
[1, 2, 3, 4]
- C:
{ 1, 1, 2, 3, 4 }
- D:
{ 1, 2, 3, 4 }
Ответ
Вопрос № 47
// counter.js
let counter = 10
export default counter
// index.js
import myCounter from "./counter.js"
myCounter += 1
console.log(myCounter)
- A:
10
- B:
11
- C:
Error
- D:
NaN
Ответ
Вопрос № 48
const name = "John"
age = 30
console.log(delete name)
console.log(delete age)
- A:
false
иtrue
- B:
John
и30
- C:
true
иtrue
- D:
undefined
иundefined
Ответ
Вопрос № 49
const numbers = [1, 2, 3, 4, 5]
const [y] = numbers
console.log(y)
- A:
[[1, 2, 3, 4, 5]]
- B:
[1, 2, 3, 4, 5]
- C:
1
- D:
[1]
Ответ
Вопрос № 50
const user = { name: "John", age: 30 }
const admin = { admin: true, ...user }
console.log(admin)
- A:
{ admin: true, user: { name: "John", age: 30 } }
- B:
{ admin: true, name: "John", age: 30 }
- C:
{ admin: true, user: [John, 30] }
- D:
{ admin: true }
Ответ
Вопрос № 51
const person = { name: "John" }
Object.defineProperty(person, "age", { value: 30 })
console.log(person)
console.log(Object.keys(person))
- A:
{ name: "John", age: 30 }
и["name", "age"]
- B:
{ name: "John", age: 30 }
и["name"]
- C:
{ name: "John"}
и["name", "age"]
- D:
{ name: "John"}
и["age"]
Ответ
Вопрос № 52
const settings = {
username: "johnsmith",
level: 19,
health: 88
}
const data = JSON.stringify(settings, ["level", "health"])
console.log(data)
- A:
{"level": 19, "health": 88}
- B:
{"username": "johnsmith"}
- C:
["level", "health"]
- D:
{"username": "johnsmith", "level": 19, "health": 88}
Ответ
Вопрос № 53
let num = 10
const increaseNumber = () => num++
const increasePassedNumber = number => number++
const num1 = increaseNumber()
const num2 = increasePassedNumber(num1)
console.log(num1)
console.log(num2)
- A:
10
и10
- B:
10
и11
- C:
11
и11
- D:
11
и12
Ответ
Вопрос № 54
const value = { number: 10 }
const multiply = (x = { ...value }) => {
console.log((x.number *= 2))
}
multiply()
multiply()
multiply(value)
multiply(value)
- A:
20 40 80 160
- B:
20 40 20 40
- C:
20 20 20 40
- D:
NaN NaN 20 40
Ответ
Вопрос № 55
[1, 2, 3, 4].reduce((x, y) => console.log(x, y))
- A:
1 2 3 3 6 4
- B:
1 2 2 3 3 4
- C:
1 undefined 2 undefined 3 undefined 4 undefined
- D:
1 2 undefined 3 undefined 4
Ответ
Вопрос № 56
// index.js
console.log('Выполнение index.js')
import { sum } from './sum.js'
console.log(sum(1, 2))
// sum.js
console.log('Выполнение sum.js')
export const sum = (a, b) => a + b
- A:
Выполнение index.js Выполнение sum.js 3
- B:
Выполнение sum.js Выполнение index.js 3
- C:
Выполнение sum.js 3 Выполнение index.js
- D:
Выполнение index.js undefined Выполнение sum.js
Ответ
Вопрос № 57
console.log(Number(2) === Number(2))
console.log(Boolean(false) === Boolean(false))
console.log(Symbol('foo') === Symbol('foo'))
- A:
true true false
- B:
false true false
- C:
true false true
- D:
true true true
Ответ
Вопрос № 58
const name = "John Smith"
console.log(name.padStart(12))
console.log(name.padStart(2))
- A:
"John Smith"
и"John Smith"
- B:
" John Smith"
и" John Smith" ("[12x whitespace]John Smith" "[2x whitespace]John Smith")
- C:
" John Smith"
и"John Smith" ("[2x whitespace]John Smith", "John Smith")
- D:
"John Smith"
и"Jo"
Ответ
Вопрос № 59
console.log("📱" + "💻")
- A:
"📱💻"
- B:
257548
- C:
undefined
- D:
Error
Ответ
Вопрос № 60
function* startGame() {
const answer = yield "Ты любишь JavaScript?"
if (answer !== "Да") {
return "Как интересно... В таком случае, что ты здесь делаешь?"
}
return "JavaScript тоже тебя любит ❤️"
}
const game = startGame()
console.log(/* 1 */) // Ты любишь JavaScript?
console.log(/* 2 */) // JavaScript тоже тебя любит ❤️
- A:
game.next("Да").value
иgame.next().value
- B:
game.next.value("Да")
иgame.next.value()
- C:
game.next().value
иgame.next("Да").value
- D:
game.next.value()
иgame.next.value("Да")
Ответ
Вопрос № 61
console.log(String.raw`Hello\nWorld!`)
- A:
Hello World!
- B:
Hello (на следующей строке) World!
- C:
Hello\nWorld!
- D:
Hello\n (на следующей строке) World!
Ответ
Вопрос № 62
async function getData() {
return await Promise.resolve("Я сделал это!")
}
const data = getData()
console.log(data)
- A:
"Я сделал это!"
- B:
Promise {\<resolved\>: "Я сделал это!"}
- C:
Promise {\<pending\>}
- D:
undefined
Ответ
Вопрос № 63
function addToList(item, list) {
return list.push(item)
}
const result = addToList("apple", ["banana"])
console.log(result)
- A:
['apple', 'banana']
- B:
2
- C:
true
- D:
undefined
Ответ
Вопрос № 64
const box = { x: 10, y: 20 }
Object.freeze(box)
const shape = box
shape.x = 100
console.log(shape)
- A:
{ x: 100, y: 20 }
- B:
{ x: 10, y: 20 }
- C:
{ x: 100 }
- D:
Error
Ответ
Вопрос № 65
const { name: myName } = { name: "John" }
console.log(name)
- A:
John
- B:
myName
- C:
undefined
- D:
Error
Ответ
Вопрос № 66
const add = () => {
const cache = {}
return num => {
if (num in cache) {
return `Из кеша! ${cache[num]}`
} else {
const result = num + 10
cache[num] = result
return `Вычислено! ${result}`
}
}
}
const addFunction = add()
console.log(addFunction(10))
console.log(addFunction(10))
console.log(addFunction(5 * 2))
- A:
Вычислено! 20 Вычислено! 20 Вычислено! 20
- B:
Вычислено! 20 Из кеша! 20 Вычислено! 20
- C:
Вычислено! 20 Из кеша! 20 Из кеша! 20
- D:
Вычислено! 20 Из кеша! 20 Error
Ответ
Вопрос № 67
const myLifeSummedUp = ["☕", "💻", "🍷", "🍫"]
for (let item in myLifeSummedUp) {
console.log(item)
}
for (let item of myLifeSummedUp) {
console.log(item)
}
- A:
0 1 2 3
и"☕" "💻" "🍷" "🍫"
- B:
"☕" "💻" "🍷" "🍫"
и"☕" "💻" "🍷" "🍫"
- C:
"☕" "💻" "🍷" "🍫"
и0 1 2 3
- D:
0 1 2 3
и{ 0: "☕", 1: "💻", 2: "🍷", 3: "🍫" }
Ответ
Вопрос № 68
const list = [1 + 2, 1 * 2, 1 / 2]
console.log(list)
- A:
["1 + 2", "1 * 2", "1 / 2"]
- B:
["12", 2, 0.5]
- C:
[3, 2, 0.5]
- D:
[1, 1, 1]
Ответ
Вопрос № 69
function sayHi(name) {
return `Hello, ${name}`
}
console.log(sayHi())
- A:
Hello
, - B:
Hello, undefined
- C:
Hello, null
- D:
Error
Ответ
Вопрос № 70
var status = "😎"
setTimeout(() => {
const status = "😍"
const data = {
status: "😉",
getStatus() {
return this.status
}
}
console.log(data.getStatus())
console.log(data.getStatus.call(this))
}, 0)
- A:
"😉"
и"😍"
- B:
"😉"
и"😎"
- C:
"😍"
и"😎"
- D:
"😎"
и"😎"
Ответ
Вопрос № 71
const person = {
name: "John",
age: 30
}
let city = person.city
city = "New York"
console.log(person)
- A:
{ name: "John", age: 30 }
- B:
{ name: "John", age: 30, city: "New York" }
- C:
{ name: "John", age: 30, city: undefined }
- D:
"New York"
Ответ
Вопрос № 72
function checkAge(age) {
if (age < 18) {
const message = "Ты слишком молод."
} else {
const message = "Ты достаточно взрослый!"
}
return message
}
console.log(checkAge(30))
- A:
"Ты слишком молод."
- B:
"Ты достаточно взрослый!"
- C:
Error
- D:
undefined
Ответ
Вопрос № 73
function getName(name) {
const hasName = /* ? */
}
- A:
!!name
- B:
name
- C:
new Boolean(name)
- D:
name.length
Ответ
Вопрос № 74
console.log("Я хочу пиццу!"[0])
- A:
""
- B:
"Я"
- C:
Error
- D:
undefined
Ответ
Вопрос № 75
function sum(num1, num2 = num1) {
console.log(num1 + num2)
}
sum(10)
- A:
NaN
- B:
20
- C:
Error
- D:
undefined
Ответ
Вопрос № 76
// module.js
export default () => "Hello World!"
export const name = "John"
// index.js
import * as data from "./module"
console.log(data)
- A:
{ default: function default(), name: "John" }
- B:
{ default: function default() }
- C:
{ default: "Hello World!", name: "John" }
- D: глобальный объект module.js
Ответ
Вопрос № 77
class Person {
constructor(name) {
this.name = name
}
}
const member = new Person("John")
console.log(typeof member)
- A:
class
- B:
function
- C:
object
- D:
string
Ответ
Вопрос № 78
let newList = [1, 2, 3].push(4)
console.log(newList.push(5))
- A:
[1, 2, 3, 4, 5]
- B:
[1, 2, 3, 5]
- C:
[1, 2, 3, 4]
- D:
Error
Ответ
Вопрос № 79
function giveMePizza() {
return "А вот и пицца!"
}
const giveMeChocolate = () => "Вот шоколад... теперь дуй в тренажерку."
console.log(giveMePizza.prototype)
console.log(giveMeChocolate.prototype)
- A:
{ constructor: ...} { constructor: ...}
- B:
{} { constructor: ...}
- C:
{ constructor: ...} {}
- D:
{ constructor: ...} undefined
Ответ
Вопрос № 80
const person = {
name: "John",
age: 30
}
for (const [x, y] of Object.entries(person)) {
console.log(x, y)
}
- A:
name John
иage 30
- B:
["name", "John"]
и["age", 30]
- C:
["name", "age"]
иundefined
- D:
Error
Ответ
Вопрос № 81
function getItems(fruitList, ...args, favoriteFruit) {
return [...fruitList, ...args, favoriteFruit]
}
console.log(getItems(["banana", "apple"], "pear", "orange"))
- A:
["banana", "apple", "pear", "orange"]
- B:
[ ["banana", "apple"], "pear", "orange" ]
- C:
["banana", "apple", ["pear"], "orange"]
- D:
Error
Ответ
Вопрос № 82
function nums(a, b) {
if
(a > b)
console.log('a больше')
else
console.log('b больше')
return
a + b
}
console.log(nums(4, 2))
console.log(nums(1, 2))
- A:
a больше, 6
иb больше, 3
- B:
a больше, undefined
иb больше, undefined
- C:
undefined
иundefined
- D:
Error
Ответ
Вопрос № 83
class Person {
constructor() {
this.name = "John"
}
}
Person = class AnotherPerson {
constructor() {
this.name = "Jane"
}
}
const member = new Person()
console.log(member.name)
- A:
John
- B:
Jane
- C:
Error
- D:
undefined
Ответ
Вопрос № 84
const info = {
[Symbol("a")]: "b"
}
console.log(info)
console.log(Object.keys(info))
- A:
{ Symbol('a'): 'b' }
и["{Symbol('a')"]
- B:
{}
и[]
- C:
{ a: 'b' }
и['a']
- D:
{ Symbol('a'): 'b' }
и[]
Ответ
Вопрос № 85
const getList = ([x, ...y]) => [x, y]
const getUser = user => { name: user.name; age: user.age }
const list = [1, 2, 3, 4]
const user = { name: "John", age: 30 }
console.log(getList(list))
console.log(getUser(user))
- A:
[1, [2, 3, 4]]
иundefined
- B:
[1, [2, 3, 4]]
и{ name: "John", age: 30 }
- C:
[1, 2, 3, 4]
и{ name: "John", age: 30 }
- D:
null
и{ name: "John", age: 30 }
Ответ
Вопрос № 86
const name = "John"
console.log(name())
- A:
SyntaxError
- B:
ReferenceError
- C:
TypeError
- D:
undefined
Ответ
Вопрос № 87
const one = (false || {} || null)
const two = (null || false || "")
const three = ([] || 0 || true)
console.log(one, two, three)
- A:
false null []
- B:
null "" true
- C:
{} "" []
- D:
null null true
Ответ
Вопрос № 88
const myPromise = () => Promise.resolve('I have resolved!')
function firstFunction() {
myPromise().then(res => console.log(res))
console.log('first')
}
async function secondFunction() {
console.log(await myPromise())
console.log('second')
}
firstFunction()
secondFunction()
- A:
I have resolved! first
иI have resolved! second
- B:
first I have resolved!
иsecond I have resolved!
- C:
I have resolved! second
иfirst I have resolved!
- D:
first I have resolved!
иI have resolved! second
Ответ
Вопрос № 89
const set = new Set()
set.add(1)
set.add("John")
set.add({ name: "John" })
for (let item of set) {
console.log(item + 2)
}
- A:
3 NaN NaN
- B:
3 7 NaN
- C:
3 John2 [object Object]2
- D:
"12" John2 [object Object]2
Ответ
Вопрос № 90
console.log(Promise.resolve(5))
- A:
5
- B:
Promise {<pending>: 5}
- C:
Promise {<resolved>: 5}
- D:
Error
Ответ
Вопрос № 91
function compareMembers(person1, person2 = person) {
if (person1 !== person2) {
console.log("Не одинаковые!")
} else {
console.log("Одинаковые!")
}
}
const person = { name: "Игорь" }
compareMembers(person)
- A:
"Не одинаковые!"
- B:
"Одинаковые!"
- C:
Error
- D:
undefined
Ответ
Вопрос № 92
const colorConfig = {
red: true,
blue: false,
green: true,
black: true,
yellow: false,
}
const colors = ["pink", "red", "blue"]
console.log(colorConfig.colors[1])
- A:
true
- B:
false
- C:
undefined
- D:
Error
Ответ
Вопрос № 93
console.log('❤️' === '❤️')
- A:
true
- B:
false
- C:
undefined
- D:
Error
Ответ
Вопрос № 94
const food = ['🍕', '🍫', '🍳', '🍔']
const info = { favoriteFood: food[0] }
info.favoriteFood = '🍝'
console.log(food)
- A:
['🍕', '🍫', '🍳', '🍔']
- B:
['🍝', '🍫', '🍳', '🍔']
- C:
['🍝', '🍕', '🍫', '🍳', '🍔']
- D:
undefined
Ответ
Вопрос № 95
let name = 'John'
function getName() {
console.log(name)
let name = 'Jane'
}
getName()
- A:
John
- B:
Jane
- C:
undefined
- D:
Error
Ответ
Вопрос № 96
function* generatorOne() {
yield ['a', 'b', 'c']
}
function* generatorTwo() {
yield* ['a', 'b', 'c']
}
const one = generatorOne()
const two = generatorTwo()
console.log(one.next().value)
console.log(two.next().value)
- A:
a
иa
- B:
a
иundefined
- C:
['a', 'b', 'c']
иa
- D:
a
и['a', 'b', 'c']
Ответ
Вопрос № 97
console.log(`${(x => x)('Я люблю')} писать код`)
- A:
Я люблю писать код
- B:
undefined писать код
- C:
${(x => x)('Я люблю') писать код
- D:
Error
Ответ
Вопрос № 98
const person = {
name: "John",
age: 29
}
const changeAge = (x = { ...person }) => x.age += 1
const changeAgeAndName = (x = { ...person }) => {
x.age += 1
x.name = "Jane"
}
changeAge(person)
changeAgeAndName()
console.log(person)
- A:
{ name: "Jane", age: 30 }
- B:
{ name: "Jane", age: 31 }
- C:
{ name: "John", age: 30 }
- D:
{ name: "John", age: 31 }
Ответ
Вопрос № 99
function sumValues(x, y, z) {
return x + y + z // 6
}
- A:
sumValues([...1, 2, 3])
- B:
sumValues([...[1, 2, 3]])
- C:
sumValues(...[1, 2, 3])
- D:
sumValues([1, 2, 3])
Ответ
Вопрос № 100
let num = 1
const list = ['a', 'b', 'c', 'd']
console.log(list[(num += 1)])
- A:
b
- B:
c
- C:
Error
- D:
undefined
Ответ
Вопрос № 101
const person = {
firstName: 'John',
lastName: 'Smith',
pet: {
name: 'Rex',
},
getFullName() {
return `${this.firstName} ${this.lastName}`
}
}
const member = {}
console.log(person.pet?.name)
console.log(person.pet?.family?.name)
console.log(person.getFullName?.())
console.log(member.getLastName?.())
- A:
undefined undefined undefined undefined
- B:
Rex undefined John Smith undefined
- C:
Rex null John Smith null
- D:
Error
Ответ
Вопрос № 102
const groceries = ['банан', 'яблоко', 'апельсин']
if (groceries.indexOf('банан')) {
console.log('Нам нужно купить бананы!')
} else {
console.log('Нам не нужно покупать бананы!')
}
- A:
"Нам нужно купить бананы!"
- B:
"Нам не нужно покупать бананы!"
- C:
undefined
- D:
1
Ответ
Вопрос № 103
const config = {
languages: [],
set language(lang) {
return this.languages.push(lang)
}
}
console.log(config.language)
- A:
function language(lang) { this.languages.push(lang }
- B:
0
- C:
[]
- D:
undefined
Ответ
Вопрос № 104
const name = 'John Smith'
console.log(!typeof name === 'object')
console.log(!typeof name === 'string')
- A:
false true
- B:
true false
- C:
false false
- D:
true true
Ответ
Вопрос № 105
const add = x => y => z => {
console.log(x, y, z)
return x + y + z
}
add(4)(5)(6)
- A:
4 5 6
- B:
6 5 4
- C:
4 function function
- D:
undefined undefined 6
Ответ
Вопрос № 106
async function* range(start, end) {
for (let i = start; i <= end; i++) {
yield Promise.resolve(i)
}
}
;(async () => {
const gen = range(1, 3)
for await (const item of gen) {
console.log(item)
}
})()
- A:
Promise {1} Promise {2} Promise {3}
- B:
Promise {<pending>} Promise {<pending>} Promise {<pending>}
- C:
1 2 3
- D:
undefined undefined undefined
Ответ
Вопрос № 107
const myFunc = ({ x, y, z }) => {
console.log(x, y, z)
}
myFunc(1, 2, 3)
- A:
1 2 3
- B:
{ 1: 1 } { 2: 2 } { 3: 3 }
- C:
{ 1: undefined } undefined undefined
- D:
undefined undefined undefined
Ответ
Вопрос № 108
const spookyItems = ['👻', '🎃', '👿']
({ item: spookyItems[3] } = { item: '💀' })
console.log(spookyItems)
- A:
["👻", "🎃", "👿"]
- B:
["👻", "🎃", "👿", "💀"]
- C:
["👻", "🎃", "👿", { item: "💀" }]
- D:
["👻", "🎃", "👿", "[object Object]"]
Ответ
Вопрос № 109
const name = 'John Smith'
const age = 30
console.log(Number.isNaN(name))
console.log(Number.isNaN(age))
console.log(isNaN(name))
console.log(isNaN(age))
- A:
true false true false
- B:
true false false false
- C:
false false true false
- D:
false true false true
Ответ
Вопрос № 110
const randomValue = 30
function getInfo() {
console.log(typeof randomValue)
const randomValue = 'John Smith'
}
getInfo()
- A:
number
- B:
string
- C:
undefined
- D:
Error
Ответ
Вопрос № 111
const myPromise = Promise.resolve('Woah some cool data')
;(async () => {
try {
console.log(await myPromise)
} catch {
throw new Error(`Oops didn't work`)
} finally {
console.log('Oh finally')
}
})()
- A:
Woah some cool data
- B:
Oh finally
- C:
Woah some cool data
иOh finally
- D:
Oops didn't work
иOh finally
Ответ
Вопрос № 112
const emojis = ['💫', ['✨', '✨', ['🍕', '🍕']]]
console.log(emojis.flat(1))
- A:
['💫', ['✨', '✨', ['🍕', '🍕']]]
- B:
['💫', '✨', '✨', ['🍕', '🍕']]
- C:
['💫', ['✨', '✨', '🍕', '🍕']]
- D:
['💫', '✨', '✨', '🍕', '🍕']
Ответ
Вопрос № 113
class Counter {
constructor() {
this.count = 0
}
increment() {
this.count++
}
}
const counterOne = new Counter()
counterOne.increment()
counterOne.increment()
const counterTwo = counterOne
counterTwo.increment()
console.log(counterOne.count)
- A:
0
- B:
1
- C:
2
- D:
3
Ответ
Вопрос № 114
const myPromise = Promise.resolve(
Promise.resolve('Promise!')
)
function funcOne() {
myPromise.then(res => res).then(res => console.log(res))
setTimeout(() => console.log('Timeout!', 0))
console.log('Last line!')
}
async function funcTwo() {
const res = await myPromise
console.log(await res)
setTimeout(() => console.log('Timeout!', 0))
console.log('Last line!')
}
funcOne()
funcTwo()
- A:
Promise! Last line! Promise! Last line! Last line! Promise!
- B:
Last line! Timeout! Promise! Last line! Timeout! Promise!
- C:
Promise! Last line! Last line! Promise! Timeout! Timeout!
- D:
Last line! Promise! Promise! Last line! Timeout! Timeout!
Ответ
Вопрос № 115
// sum.js
export default function sum(x) {
return x + x
}
// index.js
import * as sum from './sum'
/* вызов функции "sum" */
- A:
sum()
- B:
sum.sum()
- C:
sum.default()
- D: символ
*
может использоваться только при именованном экспорте
Ответ
Вопрос № 116
const handler = {
set: () => console.log('Added a new property!'),
get: () => console.log('Accessed a property!'),
}
const person = new Proxy({}, handler)
person.name = 'John'
person.name
- A:
Added a new property!
- B:
Accessed a property!
- C:
Added a new property! Accessed a property!
- D:
Error
Ответ
Вопрос № 117
const person = {
name: 'John Smith',
address: {
street: '100 Some Street',
}
}
Object.freeze(person)
person.address.street = "101 Main Street"
console.log(person.address.street)
- A:
false
- B:
100 Some Street
- C:
101 Main Street
- D:
Error
Ответ
Вопрос № 118
const add = x => x + x
function myFunc(num = 2, value = add(num)) {
console.log(num, value)
}
myFunc()
myFunc(3)
- A:
2 4
и3 6
- B:
2 NaN
и3 NaN
- C:
2 undefined
и3 6
- D:
2 4
и3 undefined
Ответ
Вопрос № 119
class Counter {
#number = 10
increment() {
this.#number++
}
getNum() {
return this.#number
}
}
const counter = new Counter()
counter.increment()
console.log(counter.#number)
- A:
10
- B:
11
- C:
undefined
- D:
Error
Ответ
Вопрос № 120
const teams = [
{ name: 'Team 1', members: ['John', 'Jane'] },
{ name: 'Team 2', members: ['Alice', 'Bob'] },
]
function* getMembers(members) {
for (let i = 0; i < members.length; i++) {
yield members[i]
}
}
function* getTeams(teams) {
for (let i = 0; i < teams.length; i++) {
/* ? */
}
}
const obj = getTeams(teams)
obj.next() // { value: "John", done: false }
obj.next() // { value: "Jane", done: false }
- A:
yield getMembers(teams[i].members)
- B:
yield* getMembers(teams[i].members)
- C:
return getMembers(teams[i].members)
- D:
return yield getMembers(teams[i].members)
Ответ
Вопрос № 121
const person = {
name: 'John Smith',
hobbies: ['coding'],
}
function addHobby(hobby, hobbies = person.hobbies) {
hobbies.push(hobby)
return hobbies
}
addHobby('running', [])
addHobby('dancing')
addHobby('baking', person.hobbies)
console.log(person.hobbies)
- A:
["coding"]
- B:
["coding", "dancing"]
- C:
["coding", "dancing", "baking"]
- D:
["coding", "running", "dancing", "baking"]
Ответ
Вопрос № 122
class Bird {
constructor() {
console.log("I'm a bird. 🐤")
}
}
class Flamingo extends Bird {
constructor() {
console.log("I'm pink. 🌸")
super()
}
}
const pet = new Flamingo()
- A:
I'm pink. 🌸
- B:
I'm pink. 🌸
иI'm a bird. 🐤
- C:
I'm a bird. 🐤
иI'm pink. 🌸
- D:
undefined
Ответ
Вопрос № 123
const person = {
name: "John Smith",
age: 30
}
console.log([...person])
// ["John Smith", 30] - как получить такой вывод?
- A: объекты являются итерируемыми по умолчанию
- B:
*[Symbol.iterator]() { for (let x in this) yield* this[x] }
- C:
*[Symbol.iterator]() { yield* Object.values(this) }
- D:
*[Symbol.iterator]() { for (let x in this) yield this }
Ответ
Вопрос № 124
let count = 0
const nums = [0, 1, 2, 3]
nums.forEach(num => {
if (num) count += 1
})
console.log(count)
- A:
1
- B:
2
- C:
3
- D:
4
Ответ
Вопрос № 125
function getFruit(fruits) {
console.log(fruits?.[1]?.[1])
}
getFruit([['🍊', '🍌'], ['🍍']])
getFruit()
getFruit([['🍍'], ['🍊', '🍌']])
- A:
null undefined 🍌
- B:
[] null 🍌
- C:
[] [] 🍌
- D:
undefined undefined 🍌
Ответ
Вопрос № 126
class Calc {
constructor() {
this.count = 0
}
increase() {
this.count++
}
}
const calc = new Calc()
new Calc().increase()
console.log(calc.count)
- A:
0
- B:
1
- C:
undefined
- D:
Error
Ответ
Вопрос № 127
const user = {
email: "e@mail.com",
password: "12345"
}
const updateUser = ({ email, password }) => {
if (email) {
Object.assign(user, { email })
}
if (password) {
user.password = password
}
return user
}
const updatedUser = updateUser({ email: "new@email.com" })
console.log(updatedUser === user)
- A:
false
- B:
true
- C:
Error
- D:
undefined
Ответ
Вопрос № 128
const fruits = ['🍌', '🍊', '🍎']
fruits.slice(0, 1)
fruits.splice(0, 1)
fruits.unshift('🍇')
console.log(fruits)
- A:
['🍌', '🍊', '🍎']
- B:
['🍊', '🍎']
- C:
['🍇', '🍊', '🍎']
- D:
['🍇', '🍌', '🍊', '🍎']
Ответ
Вопрос № 129
const animals = {}
let dog = { emoji: '🐶' }
let cat = { emoji: '🐈' }
animals[dog] = { ...dog, name: "Rex" }
animals[cat] = { ...cat, name: "Niko" }
console.log(animals[dog])
- A:
{ emoji: "🐶", name: "Rex" }
- B:
{ emoji: "🐈", name: "Niko" }
- C:
undefined
- D:
Error
Ответ
Вопрос № 130
const user = {
email: "my@email.com",
updateEmail: email => {
this.email = email
}
}
user.updateEmail("new@email.com")
console.log(user.email)
- A:
my@email.com
- B:
new@email.com
- C:
undefined
- D:
Error
Ответ
Вопрос № 131
const promise1 = Promise.resolve('First')
const promise2 = Promise.resolve('Second')
const promise3 = Promise.reject('Third')
const promise4 = Promise.resolve('Fourth')
const runPromises = async () => {
const res1 = await Promise.all([promise1, promise2])
const res2 = await Promise.all([promise3, promise4])
return [res1, res2]
}
runPromises()
.then(res => console.log(res))
.catch(er => console.log(er))
- A:
[['First', 'Second']]
и[['Fourth']]
- B:
[['First', 'Second']]
и[['Third', 'Fourth']]
- C:
[['First', 'Second']]
- D:
'Third'
Ответ
Вопрос № 132
const keys = ["name", "age"]
const values = ["John", 30]
const method = /* ? */
Object[method](keys.map((_, i) => {
return [keys[i], values[i]]
})) // { name: "John", age: 30 }
- A:
entries
- B:
values
- C:
fromEntries
- D:
forEach
Ответ
Вопрос № 133
const createMember = ({ email, address = {}}) => {
const validEmail = /.+@.+..+/.test(email)
if (!validEmail) throw new Error("Valid email please")
return {
email,
address: address ? address : null
}
}
const member = createMember({ email: "my@email.com" })
console.log(member)
- A:
{ email: "my@email.com", address: null }
- B:
{ email: "my@email.com" }
- C:
{ email: "my@email.com", address: {} }
- D:
{ email: "my@email.com", address: undefined }
Ответ
Вопрос № 134
let randomValue = { name: "John" }
randomValue = 30
if (!typeof randomValue === "string") {
console.log("Это не строка!")
} else {
console.log("Это строка!")
}
- A:
"Это не строка!"
- B:
"Это строка!"
- C:
Error
- D:
undefined
Ответ
Вопрос № 135
var car = new Vehicle("Honda", "white", "2010", "UK")
console.log(car)
function Vehicle(model, color, year, country) {
this.model = model
this.color = color
this.year = year
this.country = country
}
- A:
undefined
- B:
Error
- C:
null
- D:
{ model: "Honda", color: "white", year: "2010", country: "UK" }
Ответ
Вопрос № 136
function foo() {
let x = y = 0
x++
y++
return x
}
console.log(foo(), typeof x, typeof y)
- A:
1 undefined undefined
- B:
Error
- C:
1 undefined number
- D:
1 number number
Ответ
Вопрос № 137
function main() {
console.log('A')
setTimeout(function print() {
console.log('B')
}, 0)
console.log('C')
}
main()
- A:
A B C
- B:
B A C
- C:
A C
- D:
A C B
Ответ
Вопрос № 138
console.log(0.1 + 0.2 === 0.3)
- A:
false
- B:
true
- C:
undefined
- D:
Error
Ответ
Вопрос № 139
var y = 1
if (function f(){}) {
y += typeof f
}
console.log(y)
- A:
1function
- B:
1object
- C:
Error
- D:
1undefined
Ответ
Вопрос № 140
function foo() {
return
{
message: "Hello World"
}
}
console.log(foo())
- A:
Hello World
- B:
Object { message: "Hello World" }
- C:
undefined
- D:
Error
Ответ
Вопрос № 141
var myChars = ['a', 'b', 'c', 'd']
delete myChars[0]
console.log(myChars)
console.log(myChars[0])
console.log(myChars.length)
- A:
[empty, 'b', 'c', 'd'] empty 3
- B:
[null, 'b', 'c', 'd'] empty 3
- C:
[empty, 'b', 'c', 'd'] undefined 4
- D:
[null, 'b', 'c', 'd'] undefined 4
Ответ
Вопрос № 142
const obj = {
prop1: function() { return 0 },
prop2() { return 1 },
['prop' + 3]() { return 2 }
}
console.log(obj.prop1())
console.log(obj.prop2())
console.log(obj.prop3())
- A:
0 1 2
- B:
0 { return 1 } 2
- C:
0 { return 1 } { return 2 }
- D:
0 1 undefined
Ответ
Вопрос № 143
console.log(1 < 2 < 3)
console.log(3 > 2 > 1)
- A:
true true
- B:
true false
- C:
Error
- D:
false false
Ответ
Вопрос № 144
// обратите внимание: код выполняется в нестрогом режиме
function printNumbers (first, second, first) {
console.log(first, second, first)
}
printNumbers(1, 2, 3)
- A:
1 2 3
- B:
3 2 3
- C:
Error
- D:
1 2 1
Ответ
Вопрос № 145
// обратите внимание: код выполняется в нестрогом режиме
const printNumbersArrow = (first, second, first) => {
console.log(first, second, first)
}
printNumbersArrow(1, 2, 3)
- A:
1 2 3
- B:
3 2 3
- C:
Error
- D:
1 2 1
Ответ
Вопрос № 146
const f = () => arguments.length
console.log(f(1, 2, 3))
- A:
Error
- B:
3
- C:
undefined
- D:
null
Ответ
Вопрос № 147
console.log( String.prototype.trimLeft.name === 'trimLeft' )
console.log( String.prototype.trimLeft.name === 'trimStart' )
- A:
true false
- B:
false true
- C:
undefined
- D:
null
Ответ
Вопрос № 148
console.log(Math.max())
- A:
undefined
- B:
Infinity
- C:
0
- D:
-Infinity
Ответ
Вопрос № 149
console.log(10 == [10])
console.log(10 == [[[[[[[10]]]]]]])
- A:
true true
- B:
true false
- C:
false false
- D:
false true
Ответ
Вопрос № 150
console.log(10 + '10')
console.log(10 - '10')
- A:
20 0
- B:
1010 0
- C:
1010 10-10
- D:
NaN NaN
Ответ
Вопрос № 151
console.log([1, 2] + [3, 4])
- A:
[1, 2, 3, 4]
- B:
'[1, 2][3, 4]'
- C:
Error
- D:
'1,23,4'
Ответ
Вопрос № 152
const numbers = new Set([1, 1, 2, 3, 4])
console.log(numbers)
const browser = new Set('Firefox')
console.log(browser)
- A:
{ 1, 2, 3, 4 }
и{ "F", "i", "r", "e", "f", "o", "x" }
- B:
{ 1, 2, 3, 4 }
и{ "F", "i", "r", "e", "o", "x" }
- C:
[1, 2, 3, 4]
и["F", "i", "r", "e", "o", "x"]
- D:
{ 1, 1, 2, 3, 4 }
и{ "F", "i", "r", "e", "f", "o", "x" }
Ответ
Вопрос № 153
console.log(NaN === NaN)
- A: true
- B:
false
- C:
Error
- D:
undefined
Ответ
Вопрос № 154
const numbers = [1, 2, 3, 4, NaN]
console.log(numbers.indexOf(NaN))
- A:
4
- B:
NaN
- C:
Error
- D:
-1
Ответ
Вопрос № 155
const [a, ...b,] = [1, 2, 3, 4, 5]
console.log(a, b)
- A:
1 [2, 3, 4, 5]
- B:
1 {2, 3, 4, 5}
- C:
Error
- D:
1 [2, 3, 4]
Ответ
Вопрос № 156
async function func() {
return 10
}
console.log(func())
- A:
Promise {:10}
- B:
10
- C:
Error
- D:
Promise {:undefined}
Ответ
Вопрос № 157
async function func() {
await 10
}
console.log(func())
- A:
Promise {:10}
- B:
10
- C:
Error
- D:
Promise {:undefined}
Ответ
Вопрос № 158
function delay() {
return new Promise(resolve => setTimeout(resolve, 2000))
}
async function delayedLog(item) {
await delay()
console.log(item)
}
async function processArray(array) {
array.forEach(item => {
await delayedLog(item)
})
}
processArray([1, 2, 3, 4])
- A:
Error
- B:
1, 2, 3, 4
- C:
4, 4, 4, 4
- D:
4, 3, 2, 1
Ответ
Вопрос № 159
function delay() {
return new Promise(resolve => setTimeout(resolve, 2000))
}
async function delayedLog(item) {
await delay()
console.log(item)
}
async function process(array) {
array.forEach(async (item) => {
await delayedLog(item)
})
console.log('Process completed!')
}
process([1, 2, 3, 5])
- A:
1 2 3 5
иProcess completed!
- B:
5 5 5 5
иProcess completed!
- C:
Process completed!
и5 5 5 5
- D:
Process completed!
и1 2 3 5
Ответ
Вопрос № 160
var set = new Set()
set.add("+0")
.add("-0")
.add(NaN)
.add(undefined)
.add(NaN)
console.log(set)
- A:
Set(4) { "+0", "-0", NaN, undefined }
- B:
Set(3) { "+0", NaN, undefined }
- C:
Set(5) { "+0", "-0", NaN, undefined, NaN }
- D:
Set(4) { "+0", NaN, undefined, NaN }
Ответ
Вопрос № 161
const sym1 = Symbol('one')
const sym2 = Symbol('one')
const sym3 = Symbol.for('two')
const sym4 = Symbol.for('two')
console.log(sym1 === sym2, sym3 === sym4)
- A:
true true
- B:
true false
- C:
false true
- D:
false false
Ответ
Вопрос № 162
const sym1 = new Symbol('one')
console.log(sym1)
- A:
Error
- B:
one
- C:
Symbol('one')
- D:
Symbol
Ответ
Вопрос № 163
let myNumber = 100
let myString = "100"
if (!typeof myNumber === "string") {
console.log("It is not a string!")
} else {
console.log("It is a string!")
}
if (!typeof myString === "number"){
console.log("It is not a number!")
} else {
console.log("It is a number!")
}
- A:
Error
- B:
It is not a string!
иIt is not a number!
- C:
It is not a string!
иIt is a number!
- D:
It is a string!
иIt is a number!
Ответ
Вопрос № 164
console.log(JSON.stringify({ myArray: ['one', undefined, function() {}, Symbol('')] }))
console.log(JSON.stringify({ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]))
- A:
{ "myArray":['one', undefined, {}, Symbol] }
и{}
- B:
{ "myArray":['one', null, null, null] }
и{}
- C:
{ "myArray":['one', null, null, null] }
и"{ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]"
- D:
{ "myArray":['one', undefined, function(){}, Symbol('')] }
и{}
Ответ
Вопрос № 165
class A {
constructor() {
console.log(new.target.name)
}
}
class B extends A { constructor() { super() } }
new A()
new B()
- A:
A A
- B:
A B
- C:
B B
- D:
Error
Ответ
Вопрос № 166
const { a: x = 10, b: y = 20 } = { a: 30 }
console.log(x)
console.log(y)
- A:
30 20
- B:
10 20
- C:
10 undefined
- D:
30 undefined
Ответ
Вопрос № 167
function area({ length = 10, width = 20 }) {
console.log(length * width)
}
area()
- A:
200
- B:
Error
- C:
undefined
- D:
0
Ответ
Вопрос № 168
const props = [
{ id: 1, name: 'John'},
{ id: 2, name: 'Jane'},
{ id: 3, name: 'Bob'}
]
const [, , { name }] = props
console.log(name)
- A:
Bob
- B:
Error
- C:
undefined
- D:
John
Ответ
Вопрос № 169
function checkType(num = 1) {
console.log(typeof num)
}
checkType()
checkType(undefined)
checkType('')
checkType(null)
- A:
number undefined string object
- B:
undefined undefined string object
- C:
number number string object
- D:
number number number number
Ответ
Вопрос № 170
function add(item, items = []) {
items.push(item)
return items
}
console.log(add('Orange'))
console.log(add('Apple'))
- A:
['Orange']
и['Orange', 'Apple']
- B:
['Orange']
и['Apple']
- C:
[]
- D:
undefined
Ответ
Вопрос № 171
function greet(greeting, name, message = greeting + ' ' + name) {
console.log([greeting, name, message])
}
greet('Hello', 'John')
greet('Hello', 'John', 'Good morning!')
- A:
Error
- B:
['Hello', 'John', 'Hello John']
и['Hello', 'John', 'Good morning!']
- C:
['Hello', 'John', 'Hello John']
и['Hello', 'John', 'Hello John']
- D:
undefined
Ответ
Вопрос № 172
function outer(f = inner()) {
function inner() { return 'Inner' }
}
console.log(outer())
- A:
Error
- B:
Inner
- C:
Inner Inner
- D:
undefined
Ответ
Вопрос № 173
function myFun(x, y, ...args) {
console.log(args)
}
myFun(1, 2, 3, 4, 5)
myFun(1, 2)
- A:
[3, 4, 5]
иundefined
- B:
Error
- C:
[3, 4, 5]
и[]
- D:
[3, 4, 5]
и[undefined]
Ответ
Вопрос № 174
const obj = {'key': 'value'}
const array = [...obj]
console.log(array)
- A:
['key', 'value']
- B:
Error
- C:
[]
- D:
['key']
Ответ
Вопрос № 175
function* myGenFunc() {
yield 1
yield 2
yield 3
}
var myGenObj = new myGenFunc
console.log(myGenObj.next().value)
- A:
1
- B:
undefined
- C:
2
- D:
Error
Ответ
Вопрос № 176
function* yieldAndReturn() {
yield 1
return 2
yield 3
}
var myGenObj = yieldAndReturn()
console.log(myGenObj.next())
console.log(myGenObj.next())
console.log(myGenObj.next())
- A:
{ value: 1, done: false } { value: 2, done: true } { value: undefined, done: true }
- B:
{ value: 1, done: false } { value: 2, done: false } { value: undefined, done: true }
- C:
{ value: 1, done: false } { value: 2, done: true } { value: 3, done: true }
- D:
{ value: 1, done: false } { value: 2, done: false } { value: 3, done: true }
Ответ
Вопрос № 177
const myGenerator = (function *(){
yield 1
yield 2
yield 3
})()
for (const value of myGenerator) {
console.log(value)
break
}
for (const value of myGenerator) {
console.log(value)
}
- A:
1 2 3
и1 2 3
- B:
1 2 3
и4 5 6
- C:
1 1
- D:
1
Ответ
Вопрос № 178
const squareObj = new Square(10)
console.log(squareObj.area)
class Square {
constructor(length) {
this.length = length
}
get area() {
return this.length * this.length
}
set area(value) {
this.area = value
}
}
- A:
100
- B:
Error
- C:
10
- D:
undefined
Ответ
Вопрос № 179
function Person() { }
Person.prototype.walk = function() {
return this
}
Person.run = function() {
return this
}
let user = new Person()
let walk = user.walk
console.log(walk())
let run = Person.run
console.log(run())
- A:
undefined undefined
- B:
Person Person
- C:
Error
- D:
Window Window
Ответ
Вопрос № 180
class Vehicle {
constructor(name) {
this.name = name
}
start() {
console.log(`${this.name} vehicle started`)
}
}
class Car extends Vehicle {
start() {
console.log(`${this.name} car started`)
super.start()
}
}
const car = new Car('BMW')
console.log(car.start())
- A:
Error
- B:
BMW vehicle started
иBMW car started
- C:
BMW car started
иBMW vehicle started
- D:
BMW car started
иBMW car started
Ответ
Вопрос № 181
const user = {'age': 30}
user.age = 25
console.log(user.age)
- A:
30
- B:
25
- C:
Error
- D:
undefined
Ответ
Вопрос № 182
function a(x) {
x++
return function () {
console.log(++x)
}
}
a(1)()
a(1)()
a(1)()
let x = a(1)
x()
x()
x()
- A:
1 2 3
и1 2 3
- B:
3 3 3
и3 4 5
- C:
3 3 3
и1 2 3
- D:
1 2 3
и3 3 3
Ответ
Вопрос № 183
function Name(a, b) {
this.a = a
this.b = b
}
const me = Name('John', 'Smith')
console.log(!(a.length - window.a.length))
- A:
undefined
- B:
NaN
- C:
true
- D:
false
Ответ
Вопрос № 184
const x = function (...x) {
let k = (typeof x).length
let y = () => "freetut".length
let z = { y: y }
return k - z.y()
}
console.log(Boolean(x()))
- A:
true
- B:
1
- C:
-1
- D:
false
Ответ
Вопрос № 185
(function js(x) {
const y = (j) => j * x
console.log(y(s()))
function s() {
return j()
}
function j() {
return x ** x
}
})(3)
- A:
undefined
- B:
18
- C:
81
- D:
12
Ответ
Вопрос № 186
var tip = 100
;(function () {
console.log("I have $" + husband())
function wife() {
return tip * 2
}
function husband() {
return wife() / 2
}
var tip = 10
})()
- A:
I have $10
- B:
I have $100
- C:
I have $50
- D:
I have $NaN
Ответ
Вопрос № 187
const js = { language: "loosely type", label: "difficult" }
const edu = { ...js, level: "PhD" }
const newbie = edu
delete edu.language
console.log(Object.keys(newbie).length)
- A:
2
- B:
3
- C:
4
- D:
5
Ответ
Вопрос № 188
var candidate = {
name: "John",
age: 30
}
var job = {
frontend: "Vue or React",
backend: "Nodejs and Express",
city: "Ekaterinburg"
}
class Combine {
static get() {
return Object.assign(candidate, job)
}
static count() {
return Object.keys(this.get()).length
}
}
console.log(Combine.count())
- A:
5
- B:
6
- C:
7
- D:
8
Ответ
Вопрос № 189
var x = 1
;(() => {
x += 1
++x
})()
;((y) => {
x += y
x = x % y
})(2)
;(() => (x += x))()
;(() => (x *= x))()
console.log(x)
- A:
4
- B:
50
- C:
2
- D:
10
Ответ
Вопрос № 190
let x = {}
let y = {}
let z = x
console.log(x == y)
console.log(x === y)
console.log(x == z)
console.log(x === z)
- A:
true true true true
- B:
false false false false
- C:
true true false false
- D:
false false true true
Ответ
Вопрос № 191
console.log("hello")
setTimeout(() => console.log("hey"), 1)
setTimeout(() => console.log("yo"), 2)
setTimeout(() => console.log("world"), 0)
console.log("hi")
- A:
hello hey yo world hi
- B:
hello hi hey yo world
- C:
hello hi world hey yo
- D:
hello hi hey world yo
Ответ
Вопрос № 192
String.prototype.lengthy = () => {
console.log("hello")
}
let x = { name: "John" }
delete x
x.name.lengthy()
- A:
John
- B:
hello
- C:
undefined
- D:
Error
Ответ
Вопрос № 193
let x = {}
x.__proto__.hi = 10
Object.prototype.hi = ++x.hi
console.log(x.hi + Object.keys(x).length)
- A:
10
- B:
11
- C:
12
- D:
NaN
Ответ
Вопрос № 194
const array = (a) => {
let length = a.length
delete a[length - 1]
return a.length
}
console.log(array([1, 2, 3, 4]))
const object = (obj) => {
let key = Object.keys(obj)
let length = key.length
delete obj[key[length - 1]]
return Object.keys(obj).length
}
console.log(object({ 1: 2, 2: 3, 3: 4, 4: 5 }))
const setPropNull = (obj) => {
let key = Object.keys(obj)
let length = key.length
obj[key[length - 1]] = null
return Object.keys(obj).length
}
console.log(setPropNull({ 1: 2, 2: 3, 3: 4, 4: 5 }))
- A:
3 3 3
- B:
4 4 4
- C:
4 3 4
- D:
3 4 3
Ответ
Вопрос № 195
var a = [1, 2, 3]
var b = [1, 2, 3]
var c = [1, 2, 3]
var d = c
var e = [1, 2, 3]
var f = e.slice()
console.log(a === b)
console.log(c === d)
console.log(e === f)
- A:
true true true
- B:
false false true
- C:
true true false
- D:
false true false
Ответ
Вопрос № 196
var languages = {
name: ["javascript", "java", "python", "php", { name: "feature" }],
feature: "awesome"
}
let flag = languages.hasOwnProperty(
Object.values(languages)[0][4].name
)
;(() => {
if (flag !== false) {
console.log(
Object.getOwnPropertyNames(languages)[0].length <<
Object.keys(languages)[0].length
)
} else {
console.log(
Object.getOwnPropertyNames(languages)[1].length <<
Object.keys(languages)[1].length
)
}
})()
- A:
8
- B:
NaN
- C:
64
- D:
12
Ответ
Вопрос № 197
var person = {}
Object.defineProperties(person, {
name: {
value: "John",
enumerable: true,
},
job: {
value: "developer",
enumerable: true,
},
studying: {
value: "PhD",
enumerable: true,
},
money: {
value: "USD",
enumerable: false,
}
})
class Evaluate {
static checkFlag(obj) {
return Object.getOwnPropertyNames(obj) > Object.keys(obj)
? Object.getOwnPropertyNames(obj)
: Object.keys(obj)
}
}
const flag = Evaluate.checkFlag(person)
console.log(flag.length)
- A:
1
- B:
2
- C:
3
- D:
4
Ответ
Вопрос № 198
const id = 10
const getID = (...id) => {
id(id)
function id(id) {
console.log(typeof id)
}
}
getID(id)
- A:
Error
- B:
10
- C:
undefined
- D:
function
Ответ
Вопрос № 199
var book1 = {
name: "Name of the Rose",
getName: function () {
console.log(this.name)
}
}
var book2 = {
name: { value: "Harry Potter" }
}
var bookCollection = Object.create(book1, book2)
bookCollection.getName()
- A:
Harry Potter
- B:
Name of the rose
- C:
Error
- D:
Object object
Ответ
Вопрос № 200
(() => {
const a = Object.create({})
const b = Object.create(null)
let f1 = a.hasOwnProperty("toString")
let f2 = "toString" in b
let result =
f1 === false && f2 === false
? console.log((typeof a.toString()).length)
: console.log(b.toString())
})()
- A:
Error
- B:
undefined
- C:
0
- D:
6
Ответ
Вопрос № 201
let promise = new Promise((rs, rj) => {
setTimeout(() => rs(4), 0)
Promise.resolve(console.log(3))
console.log(2)
})
promise
.then((rs) => {
console.log(rs ? rs ** rs : rs)
return rs
})
.then((rs) => console.log(rs === 256 ? rs : rs * rs))
- A:
3 2 256 256
- B:
3 2 256 16
- C:
256 16 3 2
- D:
16 256 3 2
Ответ
Вопрос № 202
async function f() {
let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done"), 0)
})
setTimeout(() => console.log("world"), 0)
console.log(await promise)
console.log("hello")
}
f(setTimeout(() => console.log("timer"), 0))
- A:
Error
- B:
done hello world
- C:
hello done world
- D:
timer done hello world
Ответ
Вопрос № 203
class MySort {
constructor(object) {
this.object = object
}
getSort() {
return Object.entries(this.object)[0][1].sort()[
Object.values(this.object).length
]
}
}
const object = {
month: ["August", "September", "January", "December"],
}
const sortMe = new MySort(object)
console.log(sortMe.getSort())
- A:
August
- B:
September
- C:
January
- D:
December
Ответ
Вопрос № 204
const flag = [] !== !!!!![]
let f = () => {}
console.log((typeof f()).length + flag.toString().length)
- A:
NaN
- B:
12
- C:
13
- D:
14
Ответ
Вопрос № 205
(function (a, b, c) {
arguments[2] = (typeof arguments).length
c > 10 ? console.log(c) : console.log(++c)
})(1, 2, 3)
- A:
4
- B:
5
- C:
6
- D:
7
Ответ
Вопрос № 206
class Calculator {
constructor(a, b) {
this.a = a
this.b = b
}
static getFlag() {
return new Array(this.a).length == new Array(this.b)
.toString().length
}
getValue() {
return Calculator.getFlag() ? typeof this.a : typeof new Number(this.b)
}
}
const me = new Calculator(5, 5)
console.log(me.getValue())
- A:
NaN
- B:
string
- C:
object
- D:
number
Ответ
Вопрос № 207
var name = "John"
const obj = {
name: "Jane",
callMe: function () {
return this.name
}
}
let me = obj.callMe
let she = obj.callMe.bind(obj)
let result = me() === obj.callMe() ? she() : `${me()} ${she()}`
console.log(result)
- A:
undefined
- B:
John
- C:
Jane
- D:
John Jane
Ответ
Вопрос № 208
((...a) => {
const b = ["JavaScript", "Russia"]
const c = [...a, typeof a, ...b, "apple"]
console.log(c.length + c[0].length)
})(new Array(10))
- A:
5
- B:
10
- C:
15
- D:
20
Ответ
Вопрос № 209
function F(name, ...career) {
this.name = name
return Array.isArray(career) === true && typeof career === "object" ? {} : ""
}
var student = new F("John")
console.log(student.name)
- A:
John
- B:
undefined
- C:
Error
- D:
false
Ответ
Вопрос № 210
class Filter {
constructor(element) {
this.element = element
}
filter() {
return this.type() === "object" ? this.element[0].name : "hello"
}
type() {
return typeof this.element
}
}
let countries = [
{ name: "Russia", isdeveloped: true },
{ name: "Vietnam", isdeveloped: false },
]
let x = new Filter(countries)
const filter = countries.filter((item) => {
return !item.isDeveloped
})
console.log(x.filter().length + filter[0].name.length)
- A:
11
- B:
12
- C:
13
- D:
14
Ответ
Вопрос № 211
async function abc() {
console.log(8)
await Promise.resolve(2).then(console.log)
console.log(3)
}
setTimeout(() => {
console.log(1)
}, 0)
abc()
queueMicrotask(() => {
console.log(0)
})
Promise.resolve(4).then(console.log)
console.log(6)
- A:
6 8 3 0 4 2 1
- B:
8 2 3 0 4 6 1
- C:
6 8 2 0 4 3 1
- D:
8 6 2 0 4 3 1
Ответ
Вопрос № 212
const username = {
x: "youtube.com/username".length,
getMe() {
const inner = function () {
console.log(++this.x)
}
inner.bind(this)()
},
}
username.getMe()
- A:
20
- B:
21
- C:
22
- D:
23
Ответ
Вопрос № 213
function* userName() {
yield "js.pro.ru"
yield "youtube.com/username"
yield "John Smith"
}
let data = userName()
console.log((typeof data).length + data.next().value.length)
- A:
NaN
- B:
10
- C:
Error
- D:
15
Ответ
Вопрос № 214
const a = [1, 2, "one", 3, 1, "one", "two", 3]
const b = [...new Set(a)]
b.length = "one".length
console.log(b)
- A:
4
- B:
[1, 2, "one", 3, "two"]
- C:
[1, 2, "one", "two"]
- D:
[1, 2, "one"]
Ответ
Вопрос № 215
const one = function (p) {
return arguments[0]
}
const two = function (...p) {
return arguments[arguments[0]]
}
const a = [one(123), two(1, 2, 3)]
console.log(typeof a !== "object" ? a[0] : a[1])
- A:
1
- B:
2
- C:
3
- D:
123
Ответ
Вопрос № 216
class Component {
constructor(age) {
this.age = age + `${typeof Coder}`.length
}
getAge() {
return ++this.age
}
}
class Coder extends Component {
constructor(age) {
super(age)
this.age = age - `${typeof Coder}`.length
}
}
const a = new Coder(16)
console.log(a.getAge())
- A:
7
- B:
8
- C:
9
- D:
10
Ответ
Вопрос № 217
class RemoveFalse {
constructor(element) {
this.element = element
this.length = this.removeFalse().length
}
removeFalse() {
this.element = this.element.filter(Boolean)
return this.element
}
}
const theArray = [true, false, 1, 0, NaN, undefined, "", null, "string"]
const a = new RemoveFalse(theArray)
console.log(a.length)
- A:
false
- B:
true
- C:
2
- D:
3
Ответ
Вопрос № 218
const coderfarm = [1, [], {}, [], 2, 3]
const converted = Number(coderfarm instanceof Array)
const result = coderfarm.indexOf(converted + true)
console.log(result)
- A:
[]
- B:
{}
- C:
2
- D:
4
Ответ
Вопрос № 219
const converter = (arrayInput) => {
return { ...arrayInput }
}
const content = ["function", "object", "decorator"]
const checking = content[Number(false)]
const result = typeof converter(content) === content[1]
console.log(checking ? (result ? (typeof converter).length : false) : false)
- A:
6
- B:
NaN
- C:
true
- D:
8
Ответ
Вопрос № 220
function* js(length) {
for (let i = length.length; i > 0; --i) {
yield i
}
}
let getJS = js(typeof js)
let result = getJS.next().value
console.log(result + getJS.next().value)
- A:
10
- B:
14
- C:
15
- D:
16
Ответ
Вопрос № 221
var ages = [10, 15, 20, 25]
let response = []
ages.some(function (currentValue, index, ages) {
if (currentValue > ages[ages.length - index])
response.push(currentValue + ages.length)
})
console.log(response)
- A:
[20]
- B:
[20, 25]
- C:
[25, 29]
- D:
[29]
Ответ
Вопрос № 222
const getString = (string, method = false) => {
if (method === true) {
return string.slice(1, 4).length
}
return string.substr(1, 4).length
}
console.log(getString("hello", true) + getString("hello"))
- A:
6
- B:
7
- C:
8
- D:
9
Ответ
Вопрос № 223
class UserName {
name = "hello world"
getSlice(slice) {
return this.getName(slice).slice(true, this.name.length)
}
getName(space) {
return this.name.split(space)
}
}
UserName.prototype.split = function (argument) {
return this.getSlice(argument)
}
const a = new UserName()
console.log(a.split("").length)
- A:
NaN
- B:
true
- C:
10
- D:
11
Ответ
Вопрос № 224
function javaScript(node) {
let one = node.includes("I") ? " love " : " you "
return function (deno = one) {
let two = node.replace(deno, " done ")
return function (done = two) {
return (node + deno + done).length
}
}
}
console.log(javaScript("I love you")()())
- A:
20
- B:
26
- C:
23
- D:
25
Ответ
Вопрос № 225
(function (flag) {
let age = Boolean(NaN === NaN ? false : flag)
console.log(age.toString()[Number(flag)])
})([])
- A:
"f"
- B:
"t"
- C:
true
- D:
false
Ответ
Вопрос № 226
console.log(Boolean([]))
console.log(Number([]))
console.log(Number(Boolean([])))
console.log(Boolean(Number([])))
console.log(Boolean({}))
console.log(Number({}))
console.log(Number(Boolean({})))
console.log(Boolean(Number({})))
console.log(Boolean(new Boolean(false)))
- A:
true 0 1 false true 1 1 false false
- B:
true 0 1 false false NaN 1 false true
- C:
true 0 1 false false false 1 false false
- D:
true 0 1 false true NaN 1 false true
Ответ
Вопрос № 227
const myYoutube = {
name: "username",
address: "youtube.com/username",
getInfo() {
return this
},
content: () => (this === window ? myYoutube.getInfo() : this),
}
console.log(myYoutube.content().name)
- A:
username
- B:
window
- C:
NaN
- D:
undefined
Ответ
Вопрос № 228
const myArray = [1, 2, 3]
myArray.someProperty = this
Array.prototype.someOtherProperty = "hello"
let result = []
for (let key in myArray) {
result.push(key)
}
for (let key in myArray) {
if (myArray.hasOwnProperty(key)) {
result.push(key)
}
}
console.log(result.length)
- A:
10
- B:
NaN
- C:
9
- D:
7
Ответ
Вопрос № 229
const coderfarm = [1, 2, 3, 4, 5]
const [top, ...bottom] = (function (a) {
let result = a
a.unshift(new Array(3))
return result
})(coderfarm)
console.log(top.length + bottom.length)
- A:
8
- B:
9
- C:
10
- D:
11
Ответ
Вопрос № 230
let age = { number: 10 }
const getAge = (flag) => {
flag ? delete age.number : delete age
return age.number++
}
console.log(getAge(false))
console.log(age.number)
console.log(getAge(true))
console.log(age.number)
- A:
10 10 NaN NaN
- B:
10 10 undefined undefined
- C:
10 11 undefined undefined
- D:
10 11 NaN NaN
Ответ
Вопрос № 231
const f = function() {
this.x = 5;
(function() {
this.x = 3;
})();
console.log(this.x);
};
const obj = {
x: 4,
m: function() {
console.log(this.x);
},
};
f();
new f();
obj.m();
new obj.m();
f.call(f);
obj.m.call(f);
- A:
3 5 4 undefined 5 5
- B:
5 5 4 undefined 5 undefined
- C:
3 3 undefined 4 undefined 4
- D:
5 5 4 undefined 3 5