JavaScript Flashcards

(120 cards)

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
Describe array literal notation.
syntax arrayVariableName = [data1, data2, data_n];
26
How are arrays different from "plain" objects?
does not have key or property
27
What number represents the first index of an array?
zero 0
28
What is the length property of an array?
number of data in the array represent the length
29
How do you calculate the last index of an array?
arrayVariableName.length - 1
30
What is a function in JavaScript?
block od code that can be reused again and again
31
Describe the parts of a function definition.
function keyword, function name, parameter ,code block, and return
32
Describe the parts of a function call.
functionName("argument-If-Any")
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
call would be without function keyword
34
What is the difference between a parameter and an argument?
the argument has actual value
35
Why are function parameters useful?
pass information or instructions into functions
36
What two effects does a return statement have on the behavior of a function?
Produce a value & exit the function
37
Why do we log things to the console?
to label the return
38
What is a method?
the method is a function on an object
39
How do you remove the last element from an array?
variableName.pop method
40
How do you round a number down to the nearest integer?
variableName.floor()
41
How do you generate a random number?
Math.random()
42
How do you delete an element from an array?
splice()
43
How do you append an element to an array?
push() unshift()
44
How do you break a string up into an array?
split()
45
Do string methods change the original string? How would you check if you weren't sure?
no string is immutable and we can use console log to check
46
Roughly how many string methods are there according to the MDN Web docs?
a Lot of
47
Is the return value of a function or method useful in every situation?
its usefull but not in all case
48
Roughly how many array methods are there according to the MDN Web docs?
36 methods
49
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
50
Give 6 examples of comparison operators.
``` == != < <= > >= === !== ```
51
What data type do comparison expressions evaluate to?
boolean
52
What is the purpose of an if statement?
to make a decision on which blocks to run
53
Is else required in order to use an if statement?
no, it's optional
54
Describe the syntax (structure) of an if statement.
if(condition) { code to execute }
55
What are the three logical operators?
&& || !
56
How do you compare two different expressions in the same condition?
using( &&, ||, !)
57
What is the purpose of a loop?
to execute code over and over again
58
What is the purpose of a condition expression in a loop?
to check before executing a code block
59
What does "iteration" mean in the context of loops?
every time code runs within the {}
60
When does the condition expression of a while loop get evaluated?
before the iteration
61
When does the initialization expression of a for loop get evaluated?
only once
62
When does the condition expression of a for loop get evaluated?
before each express
63
When does the final expression of a for loop get evaluated?
every time until the condition became false
64
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break:
65
What does the ++ increment operator do?
Increment by one and assign it to variable
66
How do you iterate through the keys of an object?
using for-in loop
67
What event is fired when a user places their cursor in a form control?
focus event
68
What event is fired when a user's cursor leaves a form control?
blur event
69
What event is fired as a user changes the value of a form control?
input event
70
What event is fired when a user clicks the "submit" button within a ?
submit
71
What does the event.preventDefault() method do?
prevent the default behavior of elements
72
What does submitting a form without event.preventDefault() do?
refresh the page
73
What property of a form element object contains all of the form's controls.
all elements within the forms
74
What property of form a control object gets and sets its value?
value property
75
What is one risk of writing a lot of code without checking to see if it works so far?
its get more complicated if there is more line of code and gets hard to debug.
76
What is an advantage of having your console open when writing a JavaScript program?
to get insight of the code working
77
What is this in JavaScript?
it represet current object
78
What does it mean to say that this is an "implicit parameter"?
it present in every function and they dont need to declare
79
When is the value of this determined in a function; call time or definition time?
call time
80
``` 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); } }; ```
nothing function in not called yet
81
Given the above character object, what is the result of the following code snippet? Why? character.greet();
it's-a-me Mario
82
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
undefined
83
How can you tell what the value of this will be for a particular function or method definition?
we cant know
84
How can you tell what the value of this is for a particular function or method call?
``` function call will have window as this while methods will have object name of that method as this ```
85
What kind of inheritance does the JavaScript programming language use?
prototypeOf inheritance
86
What is a prototype in JavaScript?
its the predefined object which we can reuse
87
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?
bcas of prototype object
88
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
it will look into object prototype
89
What does the new operator do?
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
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
91
What does the instanceof operator do?
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
What is a "callback" function?
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
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?
setTimeout()
94
How can you set up a function to be called repeatedly without using a loop?
setInterval()
95
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0, it will immediately run the function
96
What do setTimeout() and setInterval() return?
The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval() or setTimeout();
97
What is AJAX?
ajax is a technique for loading data into part of a page without having to refresh the entire page
98
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
99
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
100
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load event
101
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
it share the prototype
102
Array.prototype.filter
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
Array.prototype.map
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
Array.prototype.reduce
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
What is "syntactic sugar"?
make easy to read
106
What is the typeof an ES6 class?
function
107
Describe ES6 class syntax.
``` class classname { methodname() { } } ```
108
What is "refactoring"?
reconstructing the code
109
How are ES Modules different from CommonJS modules?
import and export keyword vs required and module.export
110
What kind of modules can Webpack support?
``` ECMAScript modules CommonJS modules AMD modules Assets WebAssembly modules ```
111
What does fetch() return?
return promise which is fulfilled once the response is available.
112
What is the default request method used by fetch()?
GET
113
How do you specify the request method (GET, POST, etc.) when calling fetch?
``` eg fetch('https://example.com/profile/avatar', { method: 'PUT', body: formData }) ```
114
When does React call a component's componentDidMount method?
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
Name three React.Component lifecycle methods.
constructor() render() componentDidMount()
116
How do you pass data to a child component?
passing through props
117
What must the return value of myFunction be if the following expression is possible? myFunction()();
return innerfunction value.
118
``` What does this code do? const wrap = value => () => value; ```
wrap return an anonymous function that return the wrap function parameter.
119
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
when it is defined.
120
What allows JavaScript functions to "remember" values from their surroundings?
Closures.