Answer
- let - sets a variable whose value can be changed.
- const - sets a variable with a constant value (a primitive value or a reference to an object cannot be changed).
- var - sets a value similar to let, but the variable ignores scope and has a global scope. Using var is not recommended and is a bad practice.
Task What value will be assigned to the result variable
result = 12
const result = 3result = 12
var result = 3result = 12
let result = 3Answer
Var has a global scope, ignoring the block one, and is subject to hoisting, which leads to a difficult controlled logicTask: ReferenceError + TypeError - 12 - ReferenceError
3. What types of data exist in Javascript? What is the difference between them? Which data types are primitive and which are not?
Answer
- number - numeric data type. Has special values Infinity, -Infinity and Nan (computational error)
- string - data type for storing a set of characters (or character)
- boolean - logical data type. Can be true/false
- symbol -
- bigInt - numeric data type for working with large numbers ( > 253-1 and < -(253-1))
- object - Reference data type. In Javascript, functions are also objects, but sometimes they are put into a separate data type.
- null - a special value that represents "nothing", "empty" or "value unknown"
- undefined - a special value that represents "no value has been assigned"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
Task What is the result of this expressions? Why?
("b" + "a" + + "a" + "a").toLowerCase()String({})String({ property: null })String(undefined)Answer
Task: "banana" - [object Object] - [object Object] - "undefined"5. What conditional operators and null merge and assignment operators do you know? Why are they needed? What is an Optional Chain '?.'?
Task What value will be assigned to the result variable
const value = null
const result = value || 12const value = null
const result = value ?? 12const value = 0
const result = value || 12const value = 0
const result = value ?? 12const value = ""
const result = value || "12"const value = ""
const result = value ?? "12"Answer
Task: 12 - 12 | 12 - 0 | "12" - ""Answer
Answer
Answer
Answer
Task You need to write a function for which the following is true
calc(1)(2)(3)() === 6Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
Answer
21. What do you know about asynchrony in Javascript? What is a promise and a chain of promises? Tell us about async/await
Answer
Answer
Primitive values and references to objects are stored on the stack, and the object itself is stored on the heap
Answer
Memory management in JavaScript is performed automatically. In order for the garbage collector to delete an object and free up memory, the object must become unreachable (there are no references to it)https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_management
Task In what order will the messages be displayed? Why?
setTimeout(() => console.log(1), 100);
new Promise((resolve) => {
console.log(2);
resolve();
})
.then(() => {
console.log(3);
throw new Error();
})
.then(() => {
console.log(4);
})
.catch(() => {
console.log(5);
})
.then(() => {
console.log(6);
});
console.log(7);
setTimeout(() => console.log(8));