JS Fundamentals Flashcards
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.