JS Flashcards

(108 cards)

1
Q

What is the purpose of variables?

A

Variables are used to store information that will be used later

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

How do you declare a variable?

A

We declare a variable by using the var keyword followed by the variable
name, then assignment operator followed by a value

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

We use variable name, followed by the assignment
operator (=) followed by a variable 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

letters, numbers, underscore, and dollar signs, but
variables can not begin 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

It means uppercase and lowercase
letters has an affect on the word name. As an example, ”A” is different that ”a

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

Used for tasks involving text content or tasks involving words or
phrases

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

Used for tasks involving counting, adding, or mathematical operations,or anything that involves 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

Used for true/false tasks or used 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

= is an assignment operator. It sets a variable to
equal something or update a variable’s value

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

We will use the assignment operator for the variable

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

null means the value is nonexistent where undefined
means the variable has not been defined or the variable has just been declared

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

So we can know what the outputs are referring to

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

Give five examples of JavaScript primitives

A
  1. string
  2. number
  3. boolean
  4. undefined
  5. null
  6. symbol
  7. bigint
    2
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

numbers

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

What is string concatenation?

A

It is combining two strings into one string

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

this is used for string concatenation
and addition

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

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

this will add the number and then set the variable
equal to the result

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

What are objects used for?

A

Objects are a group of variables and functions used to create a model of
something from the real world

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

What are object properties?

A

Object properties are variables that are apart of an object

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

Describe object literal notation

A

Object literal notation is used to create an object. We start with a
var keyword followed by a variable name with the assignment operator and curly braces. Inside the
curly braces, we have a key and their value separated by a colon. Each key is separated by a comma

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

We would use the delete operator followed by the
object name, period, and the property we want to remove

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

to access the value of a property, we would use object, period, followed by the property name (object.newValue).
To update the value of an object property, we would used, object, open bracket, property name, close
bracket, assignment operator, and the new property value. (object[’property’] = newValue)

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

What are arrays used for?

A

Arrays are used for storing data in an organized and predictable manner.
Each value is enumerated. Store a list of data in a set order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
We start with a var keyword, followed by the array name, then assignment operator, open bracket, values stored in the array in order, and close bracket. (var array = [1,2,3])
26
How are arrays different from ”plain” objects?
Arrays differ from plain objects for arrays are ordered where objects are not
27
What number represents the first index of an array?
0
28
What is the length property of an array?
It will give the number of items in an array
29
How do you calculate the last index of an array?
We will take the length of the array and subtract 1
30
What is a function in JavaScript?
Functions are a “chunk” of code that you can use over and over again, rather than writing it out multiple times
31
Describe the parts of a function definition.
function keyword, function name (optional), open curly brace, code, return statement, and close curly brace
32
Describe the parts of a function call.
a function call is when we are calling a function to run their block of code with arguments. We need the function name, and the arguments
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function call will use specific arguments where a function definition with have a general parameter. Also, there is no curly braces in a function call or function keyword
34
What is the difference between a parameter and an argument?
A parameter is used in a function definition where argument is used in calling a function
35
Why are function parameters useful?
They are a placeholder for what kind of inputs the function will take. They could give a clue into what the function wants as an argument and used for variance for functions
36
What two effects does a return statement have on the behavior of a function?
The return statement causes the function to produce a value we can use in our program and Prevents any more code in the function’s code block from being run
37
Why do we log things to the console?
So we can verify the outputs
38
What is a method?
A method is a function which is a property of an object
39
How is a method different from any other function?
It is because they are within an object
40
How do you remove the last element from an array?
We can use the pop() method of the array object to remove the last element from an array
41
How do you round a number down to the nearest integer?
We can use the floor() method of the Math object
42
How do you generate a random number?
We can use the random() method of the Math object
43
How do you delete an element from an array?
We can use splice() method of the array object with a start index followed by 1 item
44
How do you append an element to an array?
We can use the push() method of the array object with an argument of the object we want to append
45
How do you break a string up into an array?
We can use the split() method of the string object
46
Do string methods change the original string?
How would you check if you weren’t sure? No. We can check by console.logging the original string
47
Roughly how many string methods are there according to the MDN Web docs?
50
48
Is the return value of a function or method useful in every situation?
No. Not in all cases. Like, the pop() method will remove the last value of the array, but we may not care about the last value we removed
49
Roughly how many array methods are there according to the MDN Web docs?
30 or a lot
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
Give 6 examples of comparison operators.
== (equal to), != (not equal to), > (greater than), < (less than), === (strict equal to ), !==(not strict equal to), >= (greater than or equal to), <= (less than or equal to)
52
What data type do comparison expressions evaluate to?
boolean
53
What is the purpose of an if statement?
They are used for decision making
54
Is else required in order to use an if statement?
No, else statements are not required
55
Describe the syntax (structure) of an if statement.
We start with an if keyword, followed by open parentheses, a compassion expression, then a closed parentheses, followed by an open brace, with something to happen if the condition is true, the a close brace.
56
What are the three logical operators?
&& (logical and), || (logical or), !(logical not)
57
How do you compare two different expressions in the same condition?
We can use parentheses to separate the expressions and use && or ||
58
What is the purpose of a loop?
To repeat a set of code until a certain condition is reached
59
What is the purpose of a condition expression in a loop?
To give the loop a stopping point
60
What does ”iteration” mean in the context of loops?
iteration means each time the loop code is ran
61
When does the condition expression of a while loop get evaluated?
It gets evaluated at the beginning of every iteration
62
When does the initialization expression of a for loop get evaluated?
At the beginning before the loop. It only happens one time
63
When does the condition expression of a for loop get evaluated?
At the beginning of each iteration
64
When does the final expression of a for loop get evaluated?
At the end of each iteration
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
The break keyword
66
What does the ++ increment operator do?
++ adds one to the variable and assign the new value to the variable
67
How do you iterate through the keys of an object?
We can use for in loops
68
What event is fired when a user places their cursor in a form control?
The focus event
69
What event is fired when a user’s cursor leaves a form control?
The blur event
70
What event is fired as a user changes the value of a form control?
The input event
71
What event is fired when a user clicks the ”submit” button within a ?
The submit event is attached to the form element
72
What does the event.preventDefault() method do?
The preventDefault() method of the Event interface tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be. Prevent the default behavior of the event
73
What does submitting a form without event.preventDefault() do?
Without it, the page will automatically reload when the submit button is pressed
74
What property of a form element object contains all of the form’s controls.
The elements property
75
What property of a form control object gets and sets its value?
The value property
76
What is one risk of writing a lot of code without checking to see if it works so far?
Our code could not work and it would be difficult to find where it went wrong
77
What is an advantage of having your console open when writing a JavaScript program?
So we can verify the outputs are what we expect it to be
78
What is the event.target?
This will gives us the most specific element the event is interacting with
79
What is the affect of setting an element to display: none?
The display of the element will not appear on the web page and removed from the document flow
80
What does the element.matches() method take as an argument and what does it return?
It takes CSS Selectors and returns true if the Element matches the selectors. Otherwise, false.
81
How can you retrieve the value of an element’s attribute?
We can use the getAttribute() method of the element object. It takes a string of the name of the attribute
82
At what steps of the solution would it be helpful to log things to the console?
Every time we changed the view
83
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 would need to use event listener for everything button
84
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?
We can write a conditional for every element in the loop
85
What is JSON?
JSON is a text-based data format following JavaScript object syntax that can repre- sent numbers, booleans, strings, null, arrays (ordered sequences of values), and objects (string-value mappings) made up of these values (or of other arrays and objects)
86
What are serialization and deserialization?
Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network. Deserialization is the reverse process: turning a stream of bytes into an object in memory.
87
Why are serialization and deserialization useful?
They are useful for storing, transmitting, and retrieving data
88
How do you serialize a data structure into a JSON string using JavaScript?
We can use JSON.stringify() method
89
How do you deserialize a JSON string into a data structure using JavaScript?
We can use JSON.parse() method
90
How do you store data in localStorage?
We can use the setItem() method of the localStorage object
91
How do you retrieve data from localStorage?
We can use the getItem() method of the localStorage object
92
What data type can localStorage save in the browser?
Strings
93
When does the ’beforeunload’ event fire on the window object?
The beforeunload event is fired when the window, the document and its resources are about to be unloaded. The document is still visible and the event is still cancelable at this point
94
What is a method?
A method is a function that is stored in a property of an object
95
How can you tell the difference between a method definition and a method call?
A method definition is located inside of an object literal, where a method call is begin call from an object
96
Describe method definition syntax (structure).
We start with an object in object literal notation. Next, we give the function a name, followed by a semicolon, followed by a function keyword and parenthesis, followed by an opening curly brace and the function code block.
97
Describe method call syntax (structure).
We start with an object. Then we use the object name, followed by the name of the function, opening parenthesis, the arguments, and closing parenthesis
98
How is a method different from any other function?
Methods are stored inside objects. They can not be called outside of the object
99
What is the defining characteristic of Object-Oriented Programming?
We need an object to store the data and behaviors of the object
100
What are the four ”principles” of Object-Oriented Programming?
– Abstraction - The idea of generalizing details without needing a full understanding of the me- chanics of how it actually functions – Encapsulation - The idea of limiting access to data/methods that are stored within an object – Inheritance - The mechanism of basing an object or class upon another object (prototype-based inheritance) or class (class-based inheritance) – Polymorphism - Polymorphism is the provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types.
101
What is ”abstraction”?
Abstraction is used to generalize ideas without needing to understand the full mechanics of how something works
102
What does API stand for?
Application programming interface (API) is a way for two or more computer programs to communicate with each other
103
What is the purpose of an API?
Application programming interface connects computers or pieces of software to each other
104
What is this in JavaScript?
This is an implicit parameter of all JavaScript functions
105
What does it mean to say that this is an ”implicit parameter”?
By being an implicit parameter, it means that 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
106
When is the value of this determined in a function; call time or definition time?
Call time
107
How can you tell what the value of this will be for a particular function or method definition?
the value of this can be recognized as ”the object to the left of the dot” when the function is called (as a method). If there is no value to the left of the dot when the function is called, then by default, this will be the global window object. If you cannot see the function being called, then you do not know what the value of this will be.
108
How can you tell what the value of this is for a particular function or method call?
the value of this can be recognized as ”the object to the left of the dot” when the function is called (as a method). If there is no value to the left of the dot when the function is called, then by default, this will be the global window object.