JavaScript Flashcards
Explain the difference between var, let, and const
Var is globally or locally scoped.
Const and let are block scoped.
Var and let variables can be updated later.
Const variables cannot be updated later.
Var can be re-declared.
Let and Const cannot be re-declared.
Const and let cannot be hoisted, while var can be.
What are the different data types?
String, Number, BigInt, Boolean, Undefined, Null, Symbol, Object
Explain hoisting
Hoisting is when all variable and function declarations are moved to the top of the scope.
What’s the difference between “==” and “===”?
”==” only compares values whereas “===” compares values and types.
Explain implicit type coercion
Implicit type coercion is the automatic conversion of a value from one data type to another.
Example: When a number is added to a string, the number is always converted to a string.
Is JavaScript a statically or dynamically typed language?
JavaScript is a dynamically typed language meaning the type of the variable is checked during run-time instead of during compile-time.
What is NaN?
NaN property indicates a value that is not a legal number.
Explain passed by value and passed by reference
JavaScript passes primitive data types by value and non-primitive data types by reference.
Passing by value means that the operater allocates a new space in memory and returns the address.
Passing by reference means that the operator directly passes the location of the original variable without allocating new space in memory.
What are the primitive and non-primitive types?
Primitive:
String, Number, BigInt, Boolean, Undefined, Null, Symbol
Non-Primitive:
Object
What’s the difference between primitive and non-primitive types?
Primitive types can only store a single value.
Non-primitive types can store multiple and complex values.
What is an Immediately Invoked Function?
It is a function that runs as soon as it is defined.
Explain Higher Order Functions
Higher Order Functions are functions that either take other functions as arguments or return other functions.
Explain “this” keyword
The “this” keyword refers to the object that the function is a property of and the value will always depend on the object that is invoking the function.
Explain call(), apply(), and bind()
These are all predefined methods in JavaScript.
call() invokes a method by specifying the owner object and can take arguments (separated by commas).
apply() is similar to call, but takes arguments as an array.
bind() returns a new function where the value of “this” keyword will be bound to the owner object which is provided as a parameter.
What is currying?
Currying is a technique to transform a function of arguments n to n function of one of less arguments. Example: function add (a) { return function(b){ return a + b; } }
add(3)(4)
Explain Scope and Scope Chain
Scope determines the accessibility of variables and functions within your code.
Scope chain is JavaScript engine’s process of finding a variable within the code. It starts by trying to find the variable in local scope, then moves to outer scope, and finally moves to global scope. If the variable is still not found, it will throw a reference error.
What types of scope are there and what are the differences?
Global Scope - variables and functions can be accessed from anywhere inside the code.
Function Scope - variables and functions can only be accessed within the function they have been declared.
Block Scope - Related to let and const. Var does not have block scope. Variables declared between the curly braces “{ }” can only be accessed within that block.
Explain closures
Closure is the ability for a function to store a variable for further reference even after it is executed.
What are object prototypes?
A prototype allows us to use properties and methods on an object even if the properties and methods do not exist on the current object.
What are callbacks?
Functions that are used as an argument to another function are called callback functions.
What is memoization?
Memoization is when the return value of a function is cached based on its parameters. It’s used for heavy-duty / expensive functions. If the same paramter is used, the cached result will be return instead of computing a new result to save time.
What is recursion?
Recursion is when a function calls itself repeatedly until it arrives at a result.
What is the use of a constructor function?
Constructor functions are used to create multiple objects which have similar properties and methods.
What is DOM?
DOM stands for Document Object Model. It represents the objects that comprise the structure and content of a document on the web.