JS Flashcards
Difference between let and var
let has block scope, var has function scope.
Arrow functions vs regular functions
arrow functions do not have their own this.
== vs ===
== only checks value equality and === checks type and value
What is ASI?
Automatic semicolon insertion
What are all primitive data types?
Value types:
- Number
- String
- Boolean
- BigInt
- Null
- Undefined
- symbol
Are immutable, create a new copy when operation to modify is performed.
What are non-primitive data types?
Reference types:
- Object
- Array
- Functions
- Date
- Custom objects
- RegExp
Any changes made to an object/array modifies the original object.
What is typeof used for?
It is used to return a string with the type of an unevaluated operand (object or primitive).
What is instanceof used for?
It returns true if an object is an instance of an object type.
What is the void expression?
Evaluates a given expression and returns undefined. Used to return a primitive value as undefined.
let myVar = void 10; // returns undefined
Difference between break and continue statements
Break:
- It is used to jump out of switch statements or loops.
- With a label reference, the break statement can be used to jump out of any code block.
Continue:
- breaks an interaction if a certain condition occurs then continues with the next iteration.
What is short-circuiting?
It is a conditional evaluation in which an operand may not be evaluated at all.
For … of …
Used to iterate over the values stored in an iterable data structure, such as array, set, or map. It contains the value of the element that corresponds with the current iteration of the loop. The variable initialized at the start of each iteration, and removed at the end of that iteration.
For … in …
Used to iterate over the enumerable properties of an object, including enumerable inherited properties.
push/shift/pop
- push = adds element to the end
- pop = takes element from the end
- shift = gets an element from the beginning advancing the queue (2nd element becomes 1st)
User interactions (alert, prompt, confirm)
- alert = shows a message and waits for the user to press ok
- prompt = shows modal window with a text message, an input field for the visitor and the buttons ok/cancel
- confirm = shows modal window with a question and buttons ok/cancel