JS Questions Flashcards
Enhance Knowledge of common JS topics
Lexical Scope
A variable defined outside of it’s function declaration is accessible by that function
Execution Context
A stack frame. The current code being executed.
Lexing time
JS compiles code immediately before execution let a =2 is split to let a (declaration) and a = 2 (instantiation)
Currying
A function that returns a function
How can you do Mutation Avoidance in js
Spread operator, object.assign, slice vs splice (slice returns a shallow copy)
Define Hoisting
moves all declarations to top of execution scope after lexing (splitting declarations vs instantiations) and listing them at the top
How does Inheritance work
based on prototype chain, goes all the way up to null, prototype has list of methods for that object
How does JS do Async
The event loop uses the call stack and callback queue to provide asynchronous behavior.
List Map vs ForEach differences
Map returns a new array. Each execute a function with current element as function arg
Function vs arrow() => { …
the arrow function isn’t hoisted, arrow is bounded lexically, function is bound execution context
List the differences between const let var
var is global scoped, const let block scoped (open and closed curly braces). var can be redeclared, const, let cannot. Let can be reassigned.
Async iterator
await in a for of loop
=== vs ==
Triple compares type and values. Double compares values.
What is Coercion in js?
Converts a value to another. E.g. Object to Boolean.
What does prototype do?
Allows objects to inherit features. Can be used to add features to objects.