JavaScript Flashcards

(127 cards)

1
Q

What is the purpose of variables?

A

Variables can hold any data value and can changed anytime

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

How do you declare a variable?

A

You declare using var (keyword) and variable name

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

=

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

Letter, dollar sign, and underscore to start and numbers

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

First letter shouldn’t be capitalize and every letter capitalized after is different string value than the non-capitalized string values.

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 hold values as letters/text and change

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 hold values as numbers for arithmetic

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 hold values of true or false for decision making

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

Putting a value into something

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

Assign a new value

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

They both represent empty value but null is empty on purpose - it has to be assigned to something while undefined is not assigned a 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

Gives us point of reference

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

Give five examples of JavaScript primitives

A

String, boolean, number, null, undefined, symbol

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

numeric data type

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

What is string concatenation?

A

Process of joining together two or more strings

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

Addition and string concatenation

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

adds the value of the additional data value to a variable and assigns the result to the variable

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

What are objects used for?

A

Object groups a set of variables(properties) and functions(methods) to create a model.

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

What are object properties?

A

Variables that are part of the object

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

Describe object literal notation.

A

{} with whatever properties : method name

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

with the delete operator

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 or bracket notations

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

What are arrays used for?

A

Array is used to store list of values and indexed with set order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
Array literal notation is using [] to list with data separated by commas
26
How are arrays different from "plain" objects?
Arrays are list with set order
27
What number represents the first index of an array?
[0]
28
What is the length property of an array?
It shows the total number of items in the array
29
How do you calculate the last index of an array?
[length - 1]
30
What is a function in JavaScript?
Set of statement grouped to perform a specific task and be repeatable
31
Describe the parts of a function definition.
Function keyword is used to create a new function followed by optional name and () then {} and optional return statement
32
Describe the parts of a function call.
Name of function you want to call with parentheses and arguments if needed
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition does not allow the code block to be run while function call allows function to be run. Definition requires {} for code block while call requires () for possible argument
34
Why are function parameters useful?
Function parameters are useful when replacing values to a function
35
Why do we log things to the console?
To check our mistakes in javascript by checking the console output and help debug
36
What is a method?
A method is a function which is a property of an object.
37
How is a method different from any other function?
function can be called directly while method uses dot notation with object name and method name
38
How do you remove the last element from an array?
pop()
39
How do you round a number down to the nearest integer?
Math.floor()
40
How do you generate a random number?
Math.random()
41
How do you delete an element from an array?
splice() method
42
How do you append an element to an array?
push()
43
How do you break a string up into an array?
split() method
44
Do string methods change the original string? How would you check if you weren't sure?
String method cannot be changed. You check by trying it and look for online source like MDN
45
Roughly how many string methods are there according to the MDN Web docs?
a lot
46
Is the return value of a function or method useful in every situation?
No, it is not necessary when a return is already given
47
Roughly how many array methods are there according to the MDN Web docs?
thirty
48
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
49
Give 6 examples of comparison operators.
=== (strictly equal to), != (is not equal to), >(greater than), !==, >=, <= (less than or equal to)
50
What data type do comparison expressions evaluate to?
boolean
51
What is the purpose of an if statement?
It helps in decision-making
52
Is else required in order to use an if statement?
No, else is alternative, but not everything needs alternative
53
Describe the syntax of an if statement.
if () {}
54
What are the three logical operators?
&& (logical and), || (logical or), ! (logical not)
55
How do you compare two different expressions in the same conditions?
using logical operator
56
What is the purpose of a loop?
Purpose of a loop is to repeat the same code number of times until it is false
57
What is the purpose of a condition expression in a loop?
to determine to keep going or stop the loop
58
What does "iteration" mean in the context of loops?
every time the code block runs
59
When does the condition expression of a while loop get evaluated?
beginning of the loop and each iteration
60
When does the initialization expression of a for loop get evaluated?
at the start of the loop once
61
When does the condition expression of a for loop get evaluated?
before each iteration
62
When does the final expression of a for loop get evaluated?
after each iteration
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
64
What does the ++ increment operator do?
increases the value of the variable
65
How do you iterate through the keys of an object?
for in loops
66
What is the difference between a parameter and an argument?
look it up
67
What two effects does a return statement have on the behavior of a function?
look it up
68
What is the event.target?
stores where the object originated from
69
What is the affect of setting an element to display: none?
The element disappears and no longer take space on the web page
70
What does the element.matches()
a
71
How can you retrieve the value of an element's attribute?
getAttribute()
72
At what steps of the solution would it be helpful to log things to the console?
verify the values of the variables, logging the values of the attributes
73
If you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JavaScript code be written instead?
we'd have to add an event listener to every element
74
if you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
write a conditional instead for each view
75
What is JSON?
JSON stands for JavaScript Object Notation and is a format to store and transport data. Data exchange format that is a string.
76
What are serialization and deserialization?
Serialization is the process of of turning an object in memory into a stream of bytes so you can do store on hardware or send it over the network. Deserialization is the opposite by turning a stream of bytes into an object in memory.
77
Why are serialization and deserialization useful?
They are useful in exchanging data: you can send objects over a network and it can be parsed by the reciever
78
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify - converts a JavaScript object or value to a JSON string
79
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse - data becomes a JavaScript object
80
How do you store data in localStorage?
Storage.setItem() with key: string; value: any data type
81
How do you retrieve data from localStorage?
Storage.getItem() with key as argument
82
What data type can localStorage save in the browser?
string
83
When does the 'beforeunload' event fire on the window object?
It is fired when the window, document, and its resources are about to be unloaded.
84
What is a method?
``` A method is a function which is a property of an object function stored in a property ```
85
How can you tell the difference between a method definition and a method call?
property: function() for definition | object. method()
86
Describe method definition syntax (structure).
property: function() for definition
87
Describe method call syntax (structure).
object.method()
88
What is the defining characteristic of Object-Oriented Programming?
OOP allows you to pair data and behavior
89
What are the four "principles" of Object-Oriented Programming?
Encapsulation, Abstraction, Inheritance, and Polymorphism
90
What is "abstraction"?
Working with complex things in simple ways by focusing on details of greater importance.
91
What does API stand for?
Application Programming Interface
92
What is the purpose of an API?
A set of functions that allows applications to access data and interact with external software components, operating systems, or microservices. An API delivers a user response to a system and sends the system's response back to a user.
93
How is a method different from any other function?
Methods are functions attached to objects
94
What is "this" in JavaScript?
It's the object that is acting on
95
What does it mean to say that "this" is an "implicit parameter"?
It is available in a function's code block even though it was never included in the function's parameter list or declared with var
96
When is the value of "this" determined in a function; call time or definition time?
call time
97
What does "this" refer to in the following code snippet?
Nothing but act as a placeholder
98
Given the above character object, what is the result of the following code snippet? Why?
Mario
99
Given the above character object, what is the result of the following code snippet? Why?
undefined because we're calling window.hello() and does not have property
100
How can you tell what the value of "this" will be for a particular function or method definition?
You can't know
101
How can you tell what the value of "this" is for a particular function or method call?
left of the dot
102
What kind of inheritance does the JavaScript programming language use?
prototypal inheritance
103
What is a prototype in JavaScript?
Mechanism that allows JavaScript objects to inherit features from one another
104
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?
setPrototypeOf()
105
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
_proto_
106
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.
107
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
108
What does the instanceof operator do?
to test if an object is of a given type
109
What is a "callback" function?
function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
110
Besides adding an event lister 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()
111
How can you set up a function to be called repeatedly without using a loop?
setInterval()
112
What is the default time delay if you omit the delay parameter from setTimeout() and setInterval() return?
0
113
What do setTimeout() and setInterval() return?
a timeoutID which is a positive integer identifying the timer created as a result of calling the method. IntervalID which will be an integer value
114
What is AJAX?
AJAX allows you to make asynchronous calls to a web server - this allows client browser to avoid waiting for all data to arrive before allowing the user to act once more. The main purpose of AJAX is to increase speed, performance, usability of a web application.
115
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
116
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
117
What event is fired by XMLHttpRequest objects when they are finished loading?
load event
118
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they share the same prototype property (event.target.prototype)
119
What is the JavaScript Event Loop?
event loop checks if the stack is empty. it takes the first item on the queue and pushes to the stack. Checks to see if JavaScript is not busy
120
What is different between "blocking" and "non-blocking" with respect to how code is executed?
blocking would be synchronous and blocking is code that is currently blocking the call stack and non-blocking would be non-synchronous
121
What is Array.prototype.filter useful for?
When you only want some of the data
122
What is Array.prototype.map useful for?
t is useful when you want to update or change the values inside the array list
123
What is Array.prototype.reduce useful for?
It is useful when we want single output from array
124
What must the return value of myFunction be if the following expression is possible? myFunction()();
myFunction returns another function and that returned function is what’s getting called -first () invokes first function and second () invokes second function
125
``` What does this code do? const wrap = value => () => value; ```
the value of inner function
126
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
When it is defined because when function is declared by code block the scope is determined
127
What allows JavaScript functions to "remember" values from their surroundings?
lexical environment: closure