javascript 01 Flashcards
What are the different data
types used in JavaScript?
- string
- number
- BigInt
- Boolean
- null
- undefined
- object
- symbol
Which collections of data
are ordered by a key?
Map and Set objects.
What is the proper syntax for
adding placeholders in template literals?
A dollar sign, followed by curly brackets:
${ expression }
When using the const identifier to create an instance of an object, are the properties changeable?
Yes.
An object declared as const can be modified.
The const fixes the value of the object, but not its contents.
A developer is not able to use a variable outside a function that is defined inside a function.
What could be causing this?
Variables defined inside a function cannot be accessed from anywhere outside the function, because the variable is defined only in the scope of the function.
What are some of the basic DOM data types?
- document
- node
- element
- nodeList
- attribute
- namedNodemap
Events are fired inside the browser window and tend to attach to specific items residing in the browser.
What are some of these items?
A single element, set of elements, the HTML document loaded in the current tab, or the entire browser window.
What are the most important items in your npm package.json file if you plan to publish a package?
The name and version.
Together they form unique identifier for the package.
A developer wants to set a breakpoint in his code while in the editor so they don’t have to switch to the browser. What is the in-line command for setting a breakpoint?
debugger
The debugger command will cause a breakpoint.
What are the two main properties of an error object that’s passed as an argument to catch in a try…catch construct?
name and message
What code block can be executed regardless of wether an exception was thrown or caught in a try…catch block?
The finally block can be used to execute code at the end of a try…catch block. I will run even if no catch block handles the exception.
What are some benefits of using breakpoints?
JavaScript will stop executing at each breakpoint to let you examine the current JavaScript values. After examining the values, you can resume the execution of code. You can even step from breakpoint to breakpoint.
For this code, which of the following code lines will assert the sumArr method adds the numbers in the array passed in?
let res = sumArr([2, 3, 4]);
console.assert(res===9);
Object Properties come in 3 basic types, which are they?
✢ Primitives
✢ Objects
✢ Arrays
Which are the primitive data types in JavaScript?
Number String Boolean NULL Undefined Symbol BigInt
Considering the following JavaScript object:
let bike = { gears: 10 }
Which are valid ways to access its property?
- bike.gears
- bike[“gears”]
Which of the following is a feature of prototypical inheritance?
A - A class that defines all objects of a common type. B - An in-memory object that defines properties and functions of other objects. C - Module code artifacts that define a single reusable feature D - Architecture that ensures data from some objects can be passed to other objects.
B. Because the class keyword in JavaScript is syntactic sugar, under the covers the engine is still using Object.create and there is still no class (in the object-oriented sense), just that in-memory prototype object that is the actual source of inheritance.
Variables assigned with let or const cannot be hoisted.
True or False?
True
Variables assigned with let or const are block-scoped.
True or False?
True.
Only var is not block-scoped.
Since const values cannot be reassigned, they must be initialized at the time they are declared.
True or False?
True.
If const is not initialized it will throw an error telling you either unexpected token or that it was missing an initializer in the const declaration.
const cannot be redeclared.
True or False?
True
Constants are not immutable.
- True
- False
True.
Only the object itself cannot be reassigned(mutated).
Properties within that object or array can be changed.
Template literals advantages, mention 3 of them.
- Ability to embed single and double quotation marks without using escape characters.
- MultiLine messages, with string that contains html markup spanning multiple lines.
- Tagged templates, to run the template through a function that you create.
Which of the following is not a standard function name when using promises?
- catch
- reject
- resolve
- then
- try
- try