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.