Skip to content

Latest commit

 

History

History
320 lines (231 loc) · 7.11 KB

File metadata and controls

320 lines (231 loc) · 7.11 KB

Javascript Interview Questions

1. What types of variables exist in Javascript? What is the difference between them?
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.
2. Why is using var a bad practice?

Task What value will be assigned to the result variable

result = 12
const result = 3
result = 12
var result = 3
result = 12
let result = 3
Answer Var has a global scope, ignoring the block one, and is subject to hoisting, which leads to a difficult controlled logic

Task: 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
Primitive types
  • 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))
Non-primitive types
  • object - Reference data type. In Javascript, functions are also objects, but sometimes they are put into a separate data type.
Special values
  • 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

4. Tell us about type conversion. How do I find out the data type?

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 || 12
const value = null
const result = value ?? 12
const value = 0
const result = value || 12
const value = 0
const result = value ?? 12
const value = ""
const result = value || "12"
const value = ""
const result = value ?? "12"
Answer Task: 12 - 12 | 12 - 0 | "12" - ""
6. What is the lexical scope? Function-scope vs block-scope?
Answer
7. What types of functions do you know? What are arrow functions?
Answer
8. What is hoisting?
Answer
9. What is a closure?
Answer
10. What is currying?

Task You need to write a function for which the following is true

calc(1)(2)(3)() === 6
Answer
11. What is context? What are call/apply/bind for? what is their difference?
Answer
12. Tell us about Spread syntax
Answer
13. What is destructurization? Which entities can we destructurize?
Answer
14. How do I copy an object? How to do deep copying?
Answer
15. What methods of working with an array do you know?
Answer
16. What is the peculiarity of the sort and reverse methods?
Answer
17. How does inheritance work in Javascript? What is a prototype?
Answer
18. Tell us about object property descriptors and flags
Answer
19. Tell us about Javascript classes, private and protected property methods
Answer
20. What is a generator in Javascript?
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
22. What is the difference between a reference type and a primitive in terms of storage in memory?
Answer Primitive values and references to objects are stored on the stack, and the object itself is stored on the heap
23. How the garbage collector works in Javascript?
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

24. Tell us about the loop event

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));
Answer Task: 2 - 7 - 3 - 5 - 6 - 8 - 1
25. What are polyfills? Why are they needed?
Answer
26. What are MutationObserver? Why are they needed?
Answer
27. What are ResizeObserver? Why are they needed?
Answer
28. What is Event Bubbling in JavaScript?
Answer
29. What is the difference between localstorage, sessionStorage, cookie and IndexedDB
Answer
30. What is the difference between async and defer when loading scripts?
Answer