Javascript Flashcards

(210 cards)

1
Q

What is the purpose of variables?

A

to store data for the future.

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

How do you declare a variable?

A

utilizing the var keyword to declare it.

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 the variable name (identifier) to a value using a single = sign.

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, underscore, start with $ or underscore camelCased capitalized letters but numbers cant be in the front.

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

that the same variable name but with different casing have different variable names.

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

how to hold a sequence of data characters of characters of numbers letters and other characters

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 number mainly for math

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 compare expressions as 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

assignment operator.

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 set the variable name without the keyword to another variable 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

null is the intentional absence of value where it is an object. it can be assigned but not output by java. but undefined does not have a value assigned to a variable. 1) null get data later or it was never going to be added and you will know. Java outputs undefined so developers should not.

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

logging the value without the label makes it unknown what it is being used and where it comes from.

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

Give five examples of JavaScript primitives.

A

str, num, undefined, boolean, null

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

when you combine strings utilizing , or + as any other data type becomes a 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

Addition or 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

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

it sets the value of the left side as it self plus what is on the right side

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

What are objects used for?

A

objects group together different variables datatypes can group multiple properties in association of the same object as well as being able have multiple similar object with differing properties be better organized.

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

What are object properties?

A

piece of data stored in object. easiest method to notate objects with curly brackets being assigned to a variable. with key vales.

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

Describe object literal notation.

A

defining the object and assigning to a curly brackets with a property key name : 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

delete object.property

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

through appending or using the = operator to the property and giving a value.

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

Give 6 examples of comparison operators.

A

> =
<=
<
===
!=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What data type do comparison expressions evaluate to?
boolean
26
What is the purpose of an if statement?
to compare in a conditional.
27
Is else required in order to use an if statement?
no
28
Describe the syntax (structure) of an if statement.
if condition {conditional block}
29
What are the three logical operators?
&& and || or ! not
30
How do you compare two different expressions in the same condition?
using logical operators
31
Why do we log things to the console?
for debugging or to better understand how a process works.
32
What is a method?
it is a function within an object
33
How is a method different from any other function?
its is held within an object
34
How do you remove the last element from an array?
array.pop
35
How do you round a number down to the nearest integer?
Math.floor
36
How do you generate a random number?
math.random float number between 0 and 1 representing a percentage
37
How do you delete an element from an array?
array.splice(index, how many)
38
How do you append an element to an array?
array.push
39
How do you break a string up into an array?
array.split(what it splits by) delimiter
40
Do string methods change the original string? How would you check if you weren't sure?
no. console.log
41
Is the return value of a function or method useful in every situation?
no they have return values but you wont always use it
42
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
43
What is the purpose of a loop?
a way to run a code block until a specific condition is met
44
What is the purpose of a condition expression in a loop?
To top the loop from continue running
45
What does "iteration" mean in the context of loops?
how many times it will be running
46
When does the condition expression of a for loop get evaluated?
after the initialization
47
When does the final expression of a for loop get evaluated?
After each iteration
48
When does the condition expression of a while loop get evaluated?
before running the while loop
49
When does the initialization expression of a for loop get evaluated?
the beginning of the loop
50
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break
51
What does the ++ increment operator do?
increases value by 1 by default.
52
How do you iterate through the keys of an object?
for (keys in object) { }
53
What event is fired when a user places their cursor in a form control?
focus
54
What event is fired when a user's cursor leaves a form control?
blur
55
What event is fired as a user changes the value of a form control?
input
56
What event is fired when a user clicks the "submit" button within a
?
'submit' which is fired on the form and not the button. Never have the click event listener on a button
57
What does the event.preventDefault() method do?
preventing the default behavior. for check box it will not show a check. not common you want to rid the default
58
What does submitting a form without event.preventDefault() do?
if you dont call it, page reloads and refreshes. the data is on the url but irrelevant to the point. based on initial behavior of form behaviors and action attributes. default behavior would submit to same page.
59
What property of a form element object contains all of the form's controls.
form.elements has certain properties. numbered properties, named properties in multiple forms. same thing is saved multiple times. email too message too. two out of three are saafety cases. dom is trying to pass it. have property based off of id attribute. user-email will show minus not the whole thing. using .email takes the name attribute. is relevant to form submissions. use a name attribute in every input using dot notation.
60
What property of a form control object gets and sets its value?
any form control containing the value property is get and set by VALUE
61
What is one risk of writing a lot of code without checking to see if it works so far?
if it doesn't work, you wont know whats working and not working
62
What is an advantage of having your console open when writing a JavaScript program?
see if there are any errors.
63
Does the document.createElement() method insert a new element into the page?
no
64
How do you add an element as a child to another element?
parent.appendchild(child)
65
What do you pass as the arguments to the element.setAttribute() method?
assigned value to attribute
66
What steps do you need to take in order to insert a new element into the page?
create element then add textcontent if required then parent.appendchild(child) make element, configure with class application or event listener, query for parent element, and then pass argument with appendchild.
67
What is the textContent property of an element object for?
assign value to textcontent
68
Name two ways to set the class attribute of a DOM element.
classname or set attribute or even set list.
69
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
70
What is the event.target?
it references the object to which an event happened
71
Why is it possible to listen for events on one element that actually happen its descendent elements?
bubbling allows its parents know which of its descendants are being listened to.
72
What DOM element property tells you what type of element it is?
event.target.tagName
73
What does the element.closest() method take as its argument and what does it return?
the closest item matching the argument string for css selector returning the nearest parent element with the css selector ancestor or null
74
How can you remove an element from the DOM?
element.remove()
75
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?
event delegation by putting the event listener on the ancestor
76
What is the affect of setting an element to display: none?
makes the element not visible and not take any space.
77
What does the element.matches() method take as an argument and what does it return?
78
How can you retrieve the value of an element's attribute?
79
At what steps of the solution would it be helpful to log things to the console?
every step
80
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?
81
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?
82
What is JSON?
JSON is a text-based data format
83
What are serialization and deserialization?
Serialization is when code is being transcoded to bits and stored data whereas deserialization is taking the bits and stored data into real code
84
Why are serialization and deserialization useful?
To transmit information through the internet.
85
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify(file you want serialized)
86
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse(string you want deserialized)
87
What are arrays used for?
To store a list of values
88
Describe array literal notation.
set a variable = to square brackets [] and input items
89
How are arrays different from "plain" objects?
Arrays use index values instead of keys like objects
90
What number represents the first index of an array?
0
91
What is the length property of an array?
it tells the length of the array.
92
How do you calculate the last index of an array?
array at index [array.length]
93
What is a function in JavaScript?
a set of statements that performs a task
94
Describe the parts of a function definition.
it has the keyword function, an optional name, parameters in parenthesis curly brackets executing a statement and an optional return statement with a closing curly bracket for the function code block.
95
Describe the parts of a function call.
using the defined name and simply passing an argument inside parenthesis.
96
When comparing them side-by-side, what are the differences between a function call and a function definition?
'function calls' call the defined function. it utilizes it.
97
What is the difference between a parameter and an argument?
parameters are defined within the definition while arguments utilize the function with its values as the parameters used in functions
98
Why are function parameters useful?
They are utilized as variables within the function when the function is called.
99
What two effects does a return statement have on the behavior of a function?
it returns the statement out of the function and ends the function.
100
What is a "model"?
How html page can access and contents update
101
Which "document" is being referred to in the phrase Document Object Model?
the DOM document node
102
What is the word "object" referring to in the phrase Document Object Model?
the different parts of the page loaded in the browser window
103
What is a DOM Tree?
The list of elements attribute and text in the html from parent to child
104
Give two examples of document methods that retrieve a single element from the DOM.
getElementby or queryselector
105
Give one example of a document method that retrieves multiple elements from the DOM at once.
queryselectorAll
106
Why might you want to assign the return value of a DOM query to a variable?
to access and add methods to the queried return
107
What console method allows you to inspect the properties of a DOM element object?
console.dir
108
Why would a