JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store information

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

How do you declare a variable?

A

using var before the variable name

syntax

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

How do you initialize (assign a value to) a variable?

A

variableName = value

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

What characters are allowed in variable names?

A

alphabet, number, $ and _ (variable should not start with a number)

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

What does it mean to say that variable names are “case sensitive”?

A

uppercase and lowercase variable names are considered differently

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

What is the purpose of a string?

A

to store text information

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

What is the purpose of a number?

A

to store numbers

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

What is the purpose of a boolean?

A

to make a decision in a code (either true or false)

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

What does the = operator mean in JavaScript?

A

= means assigning value to a variable

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

How do you update the value of a variable?

A

variablename = newValue

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

What is the difference between null and undefined?

A

undefined variable means a variable has not been assigned any value by the user
null means variable is assigned by the user with a null value

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

To know which variable is being printed is a console

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

Give five examples of JavaScript primitives.

A

number, string, boolean, symbol & bigint.

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

What data type is returned by an arithmetic operation?

A

Number

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

What is string concatenation?

A

joining two separate strings to one

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

What purpose(s) does the + plus operator serve in JavaScript?

A

adding numbers or concating two or more string

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

What data type is returned by comparing two values (, ===, etc)?

A

Boolean data type

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

What does the += “plus-equals” operator do?

A
\+= means adding value and storing to same variable
eg(variableName = VariableName + 'additionalString')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are objects used for?

A

to store multiple data and different types of data

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

What are object properties?

A

variable store in object

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

Describe object literal notation.

A

eg {propert:value}

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

How do you remove a property from an object?

A

using delete operator followed by object.property

syntax (delete objectname.propertyname)

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

What are the two ways to get or update the value of a property?

A

dot notaion and bracket
eg
objectname.updateProperty = newValue
objectname[‘updateProperty’] = newValue

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

What are arrays used for?

A

To store a list of data of similar type

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

Describe array literal notation.

A

syntax arrayVariableName = [data1, data2, data_n];

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

How are arrays different from “plain” objects?

A

does not have key or property

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

What number represents the first index of an array?

A

zero 0

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

What is the length property of an array?

A

number of data in the array represent the length

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

How do you calculate the last index of an array?

A

arrayVariableName.length - 1

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

What is a function in JavaScript?

A

block od code that can be reused again and again

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

Describe the parts of a function definition.

A

function keyword, function name, parameter ,code block, and return

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

Describe the parts of a function call.

A

functionName(“argument-If-Any”)

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

call would be without function keyword

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

What is the difference between a parameter and an argument?

A

the argument has actual value

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

Why are function parameters useful?

A

pass information or instructions into functions

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

What two effects does a return statement have on the behavior of a function?

A

Produce a value & exit the function

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

Why do we log things to the console?

A

to label the return

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

What is a method?

A

the method is a function on an object

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

How do you remove the last element from an array?

A

variableName.pop method

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

How do you round a number down to the nearest integer?

A

variableName.floor()

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

How do you generate a random number?

A

Math.random()

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

How do you delete an element from an array?

A

splice()

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

How do you append an element to an array?

A

push() unshift()

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

How do you break a string up into an array?

A

split()

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

Do string methods change the original string? How would you check if you weren’t sure?

A

no string is immutable and we can use console log to check

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

Roughly how many string methods are there according to the MDN Web docs?

A

a Lot of

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

Is the return value of a function or method useful in every situation?

A

its usefull but not in all case

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

Roughly how many array methods are there according to the MDN Web docs?

A

36 methods

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

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

50
Q

Give 6 examples of comparison operators.

A
==
!=
<
<=
>
>=
===
!==
51
Q

What data type do comparison expressions evaluate to?

A

boolean

52
Q

What is the purpose of an if statement?

A

to make a decision on which blocks to run

53
Q

Is else required in order to use an if statement?

A

no, it’s optional

54
Q

Describe the syntax (structure) of an if statement.

A

if(condition)
{
code to execute
}

55
Q

What are the three logical operators?

A

&&
||
!

56
Q

How do you compare two different expressions in the same condition?

A

using( &&, ||, !)

57
Q

What is the purpose of a loop?

A

to execute code over and over again

58
Q

What is the purpose of a condition expression in a loop?

A

to check before executing a code block

59
Q

What does “iteration” mean in the context of loops?

A

every time code runs within the {}

60
Q

When does the condition expression of a while loop get evaluated?

A

before the iteration

61
Q

When does the initialization expression of a for loop get evaluated?

A

only once

62
Q

When does the condition expression of a for loop get evaluated?

A

before each express

63
Q

When does the final expression of a for loop get evaluated?

A

every time until the condition became false

64
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break:

65
Q

What does the ++ increment operator do?

A

Increment by one and assign it to variable

66
Q

How do you iterate through the keys of an object?

A

using for-in loop

67
Q

What event is fired when a user places their cursor in a form control?

A

focus event

68
Q

What event is fired when a user’s cursor leaves a form control?

A

blur event

69
Q

What event is fired as a user changes the value of a form control?

A

input event

70
Q

What event is fired when a user clicks the “submit” button within a ?

A

submit

71
Q

What does the event.preventDefault() method do?

A

prevent the default behavior of elements

72
Q

What does submitting a form without event.preventDefault() do?

A

refresh the page

73
Q

What property of a form element object contains all of the form’s controls.

A

all elements within the forms

74
Q

What property of form a control object gets and sets its value?

A

value property

75
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

its get more complicated if there is more line of code and gets hard to debug.

76
Q

What is an advantage of having your console open when writing a JavaScript program?

A

to get insight of the code working

77
Q

What is this in JavaScript?

A

it represet current object

78
Q

What does it mean to say that this is an “implicit parameter”?

A

it present in every function and they dont need to declare

79
Q

When is the value of this determined in a function; call time or definition time?

A

call time

80
Q
What does this refer to in the following code snippet?
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
A

nothing function in not called yet

81
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

it’s-a-me Mario

82
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

undefined

83
Q

How can you tell what the value of this will be for a particular function or method definition?

A

we cant know

84
Q

How can you tell what the value of this is for a particular function or method call?

A
function call will have window as this
while methods will have object name of that method as this
85
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypeOf inheritance

86
Q

What is a prototype in JavaScript?

A

its the predefined object which we can reuse

87
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?

A

bcas of prototype object

88
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

it will look into object prototype

89
Q

What does the new operator do?

A

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

90
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

prototype

91
Q

What does the instanceof operator do?

A

The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

92
Q

What is a “callback” function?

A

is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

93
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout()

94
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval()

95
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0, it will immediately run the function

96
Q

What do setTimeout() and setInterval() return?

A

The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval() or setTimeout();

97
Q

What is AJAX?

A

ajax is a technique for loading data into part of a page without having to refresh the entire page

98
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

99
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest()

100
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

load event

101
Q

Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

it share the prototype

102
Q

Array.prototype.filter

A

The filter() method is an immutable JavaScript array iteration method that creates a new array filled with all the original array elements that pass the test provided by the callback function without changing the original array.

103
Q

Array.prototype.map

A

The method map of the Array prototype allows you to grab a hold of each element inside an array and apply a function to them.

104
Q

Array.prototype.reduce

A

The Array.prototype.reduce() method is an immutable JavaScript array iteration method that executes a callback function on each element of the array, resulting in a single output value.

105
Q

What is “syntactic sugar”?

A

make easy to read

106
Q

What is the typeof an ES6 class?

A

function

107
Q

Describe ES6 class syntax.

A
class classname { 
methodname() {
  }
}
108
Q

What is “refactoring”?

A

reconstructing the code

109
Q

How are ES Modules different from CommonJS modules?

A

import and export keyword vs required and module.export

110
Q

What kind of modules can Webpack support?

A
ECMAScript modules
CommonJS modules
AMD modules
Assets
WebAssembly modules
111
Q

What does fetch() return?

A

return promise which is fulfilled once the response is available.

112
Q

What is the default request method used by fetch()?

A

GET

113
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A
eg fetch('https://example.com/profile/avatar', {
  method: 'PUT',
  body: formData
})
114
Q

When does React call a component’s componentDidMount method?

A

componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.

115
Q

Name three React.Component lifecycle methods.

A

constructor()
render()
componentDidMount()

116
Q

How do you pass data to a child component?

A

passing through props

117
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

return innerfunction value.

118
Q
What does this code do?
const wrap = value => () => value;
A

wrap return an anonymous function that return the wrap function parameter.

119
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when it is defined.

120
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

Closures.