JS Fundamentals Flashcards
(34 cards)
What is the difference between undefined, null and undeclared?
Undefined is a value that has been declared but not defined.
Null is an intentional value to convey the absence of a value.
Undeclared is value that has not been declared (using var, let, const, etc.).
What is a primitive value?
Data that is not an object and has no methods and are immutable.
What are the six primitive values?
- ) String
- ) Number
- ) BigInt
- ) Boolean
- ) Undefined
- ) Symbol
Of what type are variables that are NOT primitive?
Object
What are the two basic groups of data types in JavaScript?
Primitive and Reference Types
What is hoisting?
JavaScript’s default behavior of moving variable declarations, function declarations and class declarations to the top.
What’s the difference between declarations and initializations?
Declaration: declaring a variable (ex. var text;)
Initialization: initializing a value for a variable (text = “123”)
What gets hoisted to the top?
Declarations NOT initializations!! Function declarations and NOT function expressions!
What value is a variable assigned when declared with “var”?
undefined
What value is a variable assigned when declared with “const” or “let”?
It will not be initialized. It will result in an error
Are JavaScript classes hoisted?
Yes, only class declarations. They result in same as variables declared with “const” or “let” where they are uninitialized until evaluation. Safer to write a class and then use it.
Class expressions are NOT hoisted!
Can an arrow function be used as a constructor function?
No. Arrow functions do not have its own “new.target” property so it cannot be used as a constructor function.
It cannot be called by “new” as there is no internal method that allows it.
They also don’t have the “prototype” property.
What is “new.target”?
A property that lets you detect whether a function or constructor was called using the “new” operator.
In constructors and functions invoked using the new operator, “new.target” returns a reference to the constructor or function.
In normal function calls, “new.target” is undefined.
What are the types of scope available in JavaScript?
There are two types:
- ) Local Scope
- ) Global Scope
What type of scope does JavaScript have?
Function scope, where each function creates a new scope.
What are local variables in JavaScript?
Variables that are only visible in the function where it was defined.
They are created when a function starts and deleted when the function is completed.
What are global variables in JavaScript?
Variable declared outside a function. Can be accessed by any function.
What happens when you assign a value to a variable that hasn’t been declared?
It becomes global.
What happens when you assign a value to a variable that hasn’t been declared, but you’re running in “strict mode”?
The variable does NOT become global.
What is the call method?
A method that allows you to use one method on different objects.
What is the apply method?
Like the “call” method, a method that allows you to use one method on different objects.
What’s the difference between the .call and .apply methods?
They are the same except that the “call” method accepts each parameter to be passed individually whereas the “apply” method accepts an array of parameters as the second parameter. The first parameter is the context of “this”.
How do you call the “call” method?
{method you want to be shared}.call({context of “this”}, {parameters, delimited by a comma})
How do you call the “apply” method?
{method you want to be shared}.apply({context of “this”}, [{array of parameters}])