More Basics Flashcards
How do you get all the keys in an object?
Object.getOwnPropertyNames() or Object.keys() - returns an array of object keys
How do you get all the values in an object?
Object.values() - returns an array of object values
How do you get all keys and values in an object?
Object.entries() returns an array of [key, value]
What is hoisting?
Hoisting is JavaScript’s default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).
When are hoisted variables initialized?
JavaScript only hoists declarations, not initializations. Initializations occur as written in the code.
What happens due to hoisting when you declare a variable with let?
Variables defined with let and const are hoisted to the top of the block, but not initialized.
Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared.
Using a let variable before it is declared will result in a ReferenceError.
What happens due to hoisting when you declare a variable with const?
Variables defined with let and const are hoisted to the top of the block, but not initialized.
Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared.
Using a const variable before it is declared, is a syntax errror, so the code will simply not run.
What does Javascript evaluate as a boolean False?
false, 0, ‘ ‘, “ “, null, undefined, NaN
What does Javascript evaluate as a boolean True?
‘0’, ‘false’, [ ], { }, function() { }
What is the rule of precision for decimal numbers?
Always treat them as approximations.
What does the template literal ${} do inside a string?
Evaluates whatever is inside the {}
What is one value in javascript that doesn’t equal itself?
NaN
How do you test whether a variable has a real value?
== or != null
What does the || operator do?
Returns the left value if true and the right value otherwise.
What are legal characters for binding names?
Letters, numbers, $, and _