Javascript Flashcards
(34 cards)
WithOUT ES6, how are class properties inherited from the parent?
Parent.call(property1, …propertyN)
WITH ES6, how are class properties inherited from the parent?
class Child extends Parent, call super() in constructor
WithOUT ES6, how are class methods inherited from the parent?
Child.prototype = Object.create(Parent.prototype)
How do you access class properties?
this
How do you access class methods?
prototype
How to make an AJAX or async call from the browser using vanilla JS?
new XMLHttpRequest();
req. addEventListener(“load”, reqListener);
req. open(“GET”, “http://www.example.org/example.txt”);
req. send();
How to create a new regular expression
/something/ or new RegExp()
How to specify a “character” in regex?
\w
How to specify a number in regex?
\d - Decimal
\D - non-decimal
How to test a regex?
String.prototype.match or RegExp.prototype.exec
What does the i modifier do in a regex?
case-insensitive
What is the map function?
Get a new array by applying a transformation function on each and every element in the array (immutable)
What does reduce function do?
Reduce function reduces a given list to one final result (immutable)
What are the arguments to the reduce function?
function(accumulator, currentEl, index), initialAccumulatorValue
What does filter do?
Evaluates each element of the array against a criteria, and returns a new array with only elements that return true (immutable)
What is a Pure Function?
A function which:
- Given the same input, will always return the same output.
- Produces no side effects.
How to check whether a variable is valid and not null (or) undefined?
Boolean(variable) or nullish coalescing operator (??) from ES2020
What is “hoisting”?
Variable and function declarations are put into memory during the compile phase, but stay exactly where you typed them in your code. This it allows you to use a function before you declare it in your code. JavaScript only hoists declarations, not initializations.
What is Event bubbling?
The event is handled by the innermost element first and it propagates outwards till it reaches the parent element
When to use .bind()?
Use .bind() when you want that function to later be called with a certain context (useful in events)
What does call() or apply() do?
Overwrites the function context
What are the three kinds of scopes?
Global - available everywhere,
Block - available within a bracket enclosure (let),
Local/Function - available within a function (var)
What is closure?
A function that returns another function and wraps data
A closure is an expression (most commonly, a function) that can have free variables together with an environment that binds those variables (that “closes” the expression).
What does “this” refer to in the browser?
The window object