javascript 01 Flashcards

1
Q

What are the different data

types used in JavaScript?

A
  • string
  • number
  • BigInt
  • Boolean
  • null
  • undefined
  • object
  • symbol
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which collections of data

are ordered by a key?

A

Map and Set objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the proper syntax for

adding placeholders in template literals?

A

A dollar sign, followed by curly brackets:

    ${ expression }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When using the const identifier to create an instance of an object, are the properties changeable?

A

Yes.
An object declared as const can be modified.
The const fixes the value of the object, but not its contents.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A developer is not able to use a variable outside a function that is defined inside a function.
What could be causing this?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some of the basic DOM data types?

A
  • document
  • node
  • element
  • nodeList
  • attribute
  • namedNodemap
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A single element, set of elements, the HTML document loaded in the current tab, or the entire browser window.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the most important items in your npm package.json file if you plan to publish a package?

A

The name and version.

Together they form unique identifier for the package.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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?

A

debugger

The debugger command will cause a breakpoint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the two main properties of an error object that’s passed as an argument to catch in a try…catch construct?

A

name and message

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What code block can be executed regardless of wether an exception was thrown or caught in a try…catch block?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are some benefits of using breakpoints?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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]);

A

console.assert(res===9);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Object Properties come in 3 basic types, which are they?

A

✢ Primitives
✢ Objects
✢ Arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which are the primitive data types in JavaScript?

A
Number
String 
Boolean
NULL
Undefined 
Symbol
BigInt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Considering the following JavaScript object:

let bike = { gears: 10 }

Which are valid ways to access its property?

A
  • bike.gears

- bike[“gears”]

17
Q

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.
A

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.

18
Q

Variables assigned with let or const cannot be hoisted.

True or False?

A

True

19
Q

Variables assigned with let or const are block-scoped.

True or False?

A

True.

Only var is not block-scoped.

20
Q

Since const values cannot be reassigned, they must be initialized at the time they are declared.
True or False?

A

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.

21
Q

const cannot be redeclared.

True or False?

A

True

22
Q

Constants are not immutable.

  • True
  • False
A

True.

Only the object itself cannot be reassigned(mutated).
Properties within that object or array can be changed.

23
Q

Template literals advantages, mention 3 of them.

A
  • 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.
24
Q

Which of the following is not a standard function name when using promises?

  • catch
  • reject
  • resolve
  • then
  • try
A
  • try
25
Q

What is a callback function?

A

A function passed into a function to be called later.

26
Q

Which member is executed automatically for every class that is instantiated?

  • Constructor
  • Prototype Method
  • Static Method
  • Setter Method
A
  • Constructor
27
Q

Which keyword is used to identify a derived class?

  • child
  • extends
  • this
  • prototype
A
  • extends
28
Q

When is it necessary to include the return keyword in an arrow function?

a - When the self variable has been declared.
b - When more than one expression is included in the function.
c - When an object is used to invoke the function.
d - When there is only one parameter.

A

b - When more than one expression is included in the function.

29
Q

Which syntax feature allows a function to use zero or more arguments?

=
==
{}
=> {}
...
A

30
Q

What is an advantage of declaring a variable with block scoping?

a - You don’t have to use curly braces to define a block of code.
b - You use curly braces instead of square brackets.
c - Variables declared within a code block cannot be hoisted.
d - Variables declared within a code block scope are accessible outside the block.

A

c - Variables declared within a block cannot be hoisted.

31
Q

What does the new destructuring syntax allow you to do?

a - Unpack values from arrays.
b - Convert an object to an array.
c - Compare the properties of two objects.
d - A and B
c - B and C
A

a - Unpack values from arrays.

32
Q

What is a callback function?
a - A function passed into a function to be called later.
b - A synchronous function that can block the thread.
c - A function that can be easily chained to another function.
d - A function to be executed when there is an error.

A

a - A function passed into a function to be called later.

33
Q

Which of the following is not a standard function name when using promises?

a - catch
b - reject
c - resolve
d - then
e - try
A

b - reject

34
Q

What does ‘this’ reference?

a - The arguments that a function was invoked with.
b - The context where a function was invoked.
c - The function where ‘this’ is called.
d - The object where a function was declared.

A

b - The context where a function was invoked.

35
Q

Which of the following creates a closure?

a - Declaring a variable.
b - Declaring a function.
c - Invoking a function.
d - Invoking a constructor.

A

b - Declaring a function.

36
Q

When defining a function with a function declaration, which of the following does not happen implicitly?

a - A variable name is created.
b - The function is assigned to the variable.
c - The variable is attached to the current scope.
d -The function is invoked.

A

a - A variable name is created.

37
Q

When using functions as event handlers, what are the typical parameters in the function definition?

a - The event
b - A component and the event
c - A component, the event, and a function
d - A component, the event, and a helper

A

a - The event