JS Fundamentals Flashcards

1
Q

How do JS engines work?

A
  1. Parse the script
  2. Compile script to bytecode
  3. Executes the bytecode
  • used to be a mere interpreter
  • now uses a lot of optimizations, e.g. JIT compilation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we add JS code to HTML?

A
  • external file:

- inline: console.log(“hello”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are statements?

A
  • syntax constructs and commands that perform actions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What roles do semicolons play in JS code?

A
  • separate statements
  • maybe omitted in most cases when a line break exists
  • > implicit semicolon
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does “use strict” do in JS code?

A
  • directive to enable modern JS (ES5+)

- advanced language structures enable “use strict” automatically, e.g. modules, classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a variable?

A
  • labeled storage for data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between let and const?

A
  • let enables to reassign a variable

- const does not allow reassigning a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Different data types in JS?

A
  • primitive data types: number, BigInt, string, Boolean, null, undefined, Symbols
  • non-primitive data types: Object (array, function)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
Outputs of:
Number(undefined)
Number(null)
Number(true)
Number(false)
Number("")
A
Number(undefined) // NaN
Number(null) // 0
Number(true) // 1
Number(false) // 0
Number("") // 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Outputs of:
2 + 2 + “1”
“1” + 2 + 2

A

2 + 2 + “1” // “41”

“1” + 2 + 2 // “122”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the unary + do?

A
  • nothing if applied to numbers
  • if applied to non-numbers, convert to number
  • same behavior as Number(…)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the operator = do?

A
  • assigns a value to a variable
  • low precedence
  • actually returns a value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Difference between postfix and prefix increment/decrement?
counter++
++counter

A
  • postfix: increments and returns old value

- prefix: increments and return new value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How are strings compared in JS?

A
  • letter by letter in lexicographical order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Difference between == and ===?

A
  • ==: loose equality -> compares values with type conversion to numbers
  • ===: strict equality -> compares values without type conversion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the nullish coalescing operator ?? do

A
  • return first argument if it is not null/undefined, otherwise second one
result = a ?? b
result = (a !== null && a !== undefined) ? a : b
17
Q

Differences between Function Expression and Function Declaration?

A

Function Expression:

  • function created inside an expression or inside another syntax construct
  • not hoisted (are created when execution flow reaches them)

Function Declaration:

  • function declared as a separate statement in the main code flow
  • hoisted (processed before the code block is executed)
18
Q

What are transpilers?

A
  • software that can parse modern code and rewrite it using older syntax
  • enables dev to use modern language syntax features without worrying about backward compatibility
  • Babel is one of the most modern
19
Q

What are polyfills?

A
  • new language features can also contain built-in functions, e.g. Array.flatMap
  • polyfills functions that fill the gap of missing functions