JavaScript Flashcards

(109 cards)

1
Q

What is the purpose of variables?

A

tto tem,porarily store information for the computer to use in order to get the desired result

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 a keyword like var, const or let

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

you assign it a value with the equal operator

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 and _underscore not 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

it means, the the same word written with different cases are two different variables

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

holds words, inside quotation marks, can add written information for user, works with any kind of text

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 allow the computer to calculate as well as moving elements on a page, holds numeric value;

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 give the computer true or false data, it helps ‘check’ things, allows for 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

ther assignment operator assigns a value to variable names

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

you do not have to declare it again, you just use the assignment operator

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 is the immediate value of a variable if it hasn’t been assigned a value or for formal arguments where there are nno actual arguments

In computer science, a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. The meaning of a null reference varies among language implementations.
null can also be used for a place to store a value to be changed later

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 that you keep track of your consoles
tells you what line number you’re on

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

Give five examples of JavaScript primitives.

A

null, undefined, string data, numeric data, boolean data

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

Difference between primitive and reference data types

A

primitives stores the variable in memory location
reference stores the address of where the information is

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

What data type is returned by an arithmetic operation?

A

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.

A number

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

What is string concatenation?

A

Concatenate just means “join together”. To join together strings in JavaScript you can use a different type of string, called a template literal.

‘string’ + ‘string’
${string}

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

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

A

addition of number values, and string concatenation
+ operator if it receives two numbers it knows it needs to add,
if it receives a string, it knows to concantenate

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

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

A

true or false, boolean

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

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

A

adds a value to the right and updates the variable

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

What are objects used for?

A

objects group together a set of variables and functions that create a model of something that exists in the real world

grouping variables together

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

What are object properties?

A

in an object, variables are known as properties - they can hold information like the name of a hotel
name: ‘Hilton’ -> that is the property

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

Describe object literal notation.

A

var object = { name(key): louisa(value) }
key value pairs

var keyword var object ope

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

How do you remove a property from an object?

A

delete operator
delete pet.name

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

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

A

person.name
person[name]
dot or bracket notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
why use dot versus bracket notation?
bracket notation allows us to use a variable to store a property name student.name can only be name var prop = 'color' vehicle[prop] = 'white' ^^ bracket is substition bracket also allows to accessor create an illegal variable names look at pictures
26
Objects are addresses, they point to the first point of data you're storing a reference to a memory base that points to the first value reference data point
27
What are arrays used for?
to keep lists of data
28
Describe array literal notation.
variable is assign to the array object
29
How are arrays different from "plain" objects?
30
What number represents the first index of an array?
31
What is the length property of an array?
32
How do you calculate the last index of an array?
the length. -1
32
How do you calculate the last index of an array?
the length. -1
33
What is a function in JavaScript?
34
Describe the parts of a function definition.
function ex(hi, yo) { var ex = y return x}
35
Describe the parts of a function call.
function() Calling the function actually performs the specified actions with the indicated parameters. For example, if you define the function square, you could call it as follows: code inside the function will execute when "something" invokes (calls) the function: When an event occurs (when a user clicks a button) When it is invoked (called) from JavaScript code Automatically (self invoked)
36
When comparing them side-by-side, what are the differences between a function call and a function definition?
Once defined, a function is just another kind of object. However, it is special in that it can be called. A function must be called for the code within its code block to run. option key word Parameter { code black}
37
What is the difference between a parameter and an argument?
Function parameters are listed inside the parentheses () in the function definition. Function arguments are the values received by the function when it is invoked. Inside the function, the arguments (the parameters) behave as local variables.
38
Why are function parameters useful?
act as variables and argyu8ments act more like value;
39
What two effects does a return statement have on the behavior of a function?
40
Why do we log things to the console?
The JavaScript console is a debugging tool. It is where the browser prints errors and warnings as they occur in your JavaScript code.
41
What is a method?
A method is a function which is a property of an object. Random is the function - the value is what the function does There are two kinds of methods: instance methods which are built-in tasks performed by an object instance, or static methods which are tasks that are called directly on an object constructor.
42
How is a method different from any other function?
In JavaScript functions themselves are objects, so, in that context, a method is actually an object reference to a function. Other than being a property of an object, difference is only that the method is assignedf to a property
43
How do you remove the last element from an array?
array.pop()
44
How do you round a number down to the nearest integer?
Math.floor
45
How do you generate a random number?
Math.floor(Math.random());
46
How do you delete an element from an array?
array.splice(start, howMany)
47
How do you append an element to an array?
array.push()
48
How do you break a string up into an array?
string.split()
49
Do string methods change the original string? How would you check if you weren't sure?
No, but you can assign the modified string to a new variable MDN or console.log
50
Roughly how many string methods are there according to the MDN Web docs?
too many
51
Is the return value of a function or method useful in every situation?
if you don't need the return value of something, the return value isnt useful, for instance splice
52
Roughly how many array methods are there according to the MDN Web docs?
alot
53
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
54
Math.max(1, 2, 3) - is 3
The Math.max() function returns the largest of the zero or more numbers given as input parameters, or NaN if any parameter isn't a number and can't be converted into one.
55
Give 6 examples of comparison operators.
56
What data type do comparison expressions evaluate to?
57
What is the purpose of an if statement?
58
Is else required in order to use an if statement?
59
Describe the syntax (structure) of an if statement.
60
What are the three logical operators?
61
How do you compare two different expressions in the same condition?
62
• What is the className property of element objects?
The className property of the Element interface gets and sets the value of the class attribute of the specified element. A string variable representing the class or space-separated classes of the current element.
63
How do you update the CSS class attribute of an element using JavaScript?
query the element and add the property on the variable that is queryselected, you need to use = sign
64
What is the textContent property of element objects?
The textContent property of the Node interface represents the text content of the node and its descendants. gets and sets the node elements
65
How do you update the text within an element using JavaScript?
with an assignment operator
66
Is the event parameter of an event listener callback always useful?
67
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
68
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
69
element.classlist toggle remove
70
textContent = ''; destroys all child elements
71
What does the transform property do?
The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual formatting model. If the property has a value different than none, a stacking context will be created. In that case, the element will act as a containing block for any position: fixed; or position: absolute; elements that it contains.
72
Give four examples of CSS transform functions.
transform: matrix(1, 2, 3, 4, 5, 6); transform: translate(120px, 50%); transform: scale(2, 0.5); transform: skew(30deg, 20deg); transform: scale(0.5) translate(-100%, -100%);
73
What event is fired when a user places their cursor in a form control?
focus event
74
What event is fired when a user's cursor leaves a form control?
blur
75
What event is fired as a user changes the value of a form control?
input
76
What event is fired when a user clicks the "submit" button within a form?
'submit'
77
What does the event.preventDefault() method do? What does submitting a form without event.preventDefault() do?
stops page from refreshing, submit forms by default refresh and lose inouts
78
What property of a form element object contains all of the form's controls.
element
79
What property of a form control object gets and sets its value?
name and value VALUE PROPERTY
80
What is one risk of writing a lot of code without checking to see if it works so far?
waste of time
81
What is an advantage of having your console open when writing a JavaScript program?
You see it live and catch mistakes
82
Give two examples of media features that you can query in an @media rule.
Orientation max-width min-width height
83
Which HTML meta tag is used in mobile-responsive web pages?
View port
84
PRINT version is for just printing the text on the page
85
What is the event.target?
The read-only target property of the Event interface is a reference to the object onto which the event was dispatched. The event.target property can be used in order to implement event delegation. The actual thing that is clicked
86
Why is it possible to listen for events on one element that actually happen its descendent elements?
because of bubbling?
87
What DOM element property tells you what type of element it is?
tagName
88
What does the element.closest() method take as its argument and what does it return?
the elemnt closest to the event.target
89
How can you remove an element from the DOM?
element.remove()
90
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
91
What is the event.target?
92
What is the affect of setting an element to display: none?
no display
93
What does the element.matches() method take as an argument and what does it return?
94
How can you retrieve the value of an element's attribute?
95
At what steps of the solution would it be helpful to log things to the console?
96
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?
97
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?
98
What is JSON?
99
What are serialization and deserialization?
100
Why are serialization and deserialization useful?
101
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify
102
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
103
What is JSON
avaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax
104
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. breakes into bytes
105
How do you store data in localStorage?
localStorage.setItem('key', 'value')
106
How do you retrieve data from localStorage?
getItem
107
What data type can localStorage save in the browser?
keyName A string containing the name of the key you want to create/update. keyValue A string containing the value you want to give the key you are creating/updating.
108
When does the 'beforeunload' event fire on the window object?
Does whatever it needs to do before the page refreshes or changes