JavaScript Flashcards

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
Q

why use dot versus bracket notation?

A

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

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

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

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

What are arrays used for?

A

to keep lists of data

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

Describe array literal notation.

A

variable is assign to the array object

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

How are arrays different from “plain” objects?

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

What number represents the first index of an array?

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

What is the length property of an array?

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

How do you calculate the last index of an array?

A

the length. -1

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

How do you calculate the last index of an array?

A

the length. -1

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

What is a function in JavaScript?

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

Describe the parts of a function definition.

A

function ex(hi, yo) {
var ex = y
return x}

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

Describe the parts of a function call.

A

function()
Callingthe function actually performs the specified actions with the indicated parameters. For example, if you define the functionsquare, 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)

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

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

A

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}

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

What is the difference between a parameter and an argument?

A

Functionparametersare listed inside the parentheses () in the function definition.
Functionargumentsare thevaluesreceived by the function when it is invoked.
Inside the function, the arguments (the parameters) behave as local variables.

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

Why are function parameters useful?

A

act as variables and argyu8ments act more like value;

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

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

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

Why do we log things to the console?

A

The JavaScript console is a debugging tool. It is where the browser prints errors and warnings as they occur in your JavaScript code.

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

What is a method?

A

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.

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

How is a method different from any other function?

A

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

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

How do you remove the last element from an array?

A

array.pop()

44
Q

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

A

Math.floor

45
Q

How do you generate a random number?

A

Math.floor(Math.random());

46
Q

How do you delete an element from an array?

A

array.splice(start, howMany)

47
Q

How do you append an element to an array?

A

array.push()

48
Q

How do you break a string up into an array?

A

string.split()

49
Q

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

A

No, but you can assign the modified string to a new variable
MDN or console.log

50
Q

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

A

too many

51
Q

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

A

if you don’t need the return value of something, the return value isnt useful, for instance splice

52
Q

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

A

alot

53
Q

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

A

MDN

54
Q

Math.max(1, 2, 3) - is 3

A

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
Q

Give 6 examples of comparison operators.

A
56
Q

What data type do comparison expressions evaluate to?

A
57
Q

What is the purpose of an if statement?

A
58
Q

Is else required in order to use an if statement?

A
59
Q

Describe the syntax (structure) of an if statement.

A
60
Q

What are the three logical operators?

A
61
Q

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

A
62
Q

• What is the className property of element objects?

A

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
Q

How do you update the CSS class attribute of an element using JavaScript?

A

query the element and add the property on the variable that is queryselected, you need to use = sign

64
Q

What is the textContent property of element objects?

A

The textContent property of the Node interface represents the text content of the node and its descendants.

gets and sets the node elements

65
Q

How do you update the text within an element using JavaScript?

A

with an assignment operator

66
Q

Is the event parameter of an event listener callback always useful?

A
67
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A
68
Q

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A
69
Q

element.classlist
toggle
remove

A
70
Q

textContent = ‘’; destroys all child elements

A
71
Q

What does the transform property do?

A

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
Q

Give four examples of CSS transform functions.

A

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
Q

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

A

focus event

74
Q

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

A

blur

75
Q

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

A

input

76
Q

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

A

‘submit’

77
Q

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

A

stops page from refreshing, submit forms by default refresh and lose inouts

78
Q

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

A

element

79
Q

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

A

name and value
VALUE PROPERTY

80
Q

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

A

waste of time

81
Q

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

A

You see it live and catch mistakes

82
Q

Give two examples of media features that you can query in an @media rule.

A

Orientation
max-width
min-width
height

83
Q

Which HTML meta tag is used in mobile-responsive web pages?

A

View port

84
Q

PRINT version is for just printing the text on the page

A
85
Q

What is the event.target?

A

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
Q

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

because of bubbling?

87
Q

What DOM element property tells you what type of element it is?

A

tagName

88
Q

What does the element.closest() method take as its argument and what does it return?

A

the elemnt closest to the event.target

89
Q

How can you remove an element from the DOM?

A

element.remove()

90
Q

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?

A
91
Q

What is the event.target?

A
92
Q

What is the affect of setting an element to display: none?

A

no display

93
Q

What does the element.matches() method take as an argument and what does it return?

A
94
Q

How can you retrieve the value of an element’s attribute?

A
95
Q

At what steps of the solution would it be helpful to log things to the console?

A
96
Q

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?

A
97
Q

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?

A
98
Q

What is JSON?

A
99
Q

What are serialization and deserialization?

A
100
Q

Why are serialization and deserialization useful?

A
101
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify

102
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse

103
Q

What is JSON

A

avaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax

104
Q

What are serialization and deserialization?

A

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
Q

How do you store data in localStorage?

A

localStorage.setItem(‘key’, ‘value’)

106
Q

How do you retrieve data from localStorage?

A

getItem

107
Q

What data type can localStorage save in the browser?

A

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
Q

When does the ‘beforeunload’ event fire on the window object?

A

Does whatever it needs to do before the page refreshes or changes