JavaScript Flashcards

(101 cards)

1
Q

What is a variable?

A

A way to hold data

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

Why are variables useful?

A

It can hold data that changes

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

What two special characters can a variable begin with?

A

dollar sign and underscore

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

How do you declare a variable?

A

Using the keyword “var”

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

How do you assign a value to a variable?

A

With the assignment operator “=”

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

Are variables case sensitive?

A

Yes

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

Which words cannot be used as variable names?

A

can’t start with a digit, no punctuation or special characters, keywords

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

What is a string?

A

datatype to represent text stored with quotation marks

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

What is the string concatenation operator?

A

+

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

What is the difference when it comes to using single quotes or double quotes ( ‘ ‘ or “ “ )?

A

No difference, but has to start and end with same quote

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

How do you escape quotation characters?

A

Backslash before the quote to let the interpreter know that it is part of the string instead the end of it.

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

What is type coercion?

A

JS will convert that value to the type it needs

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

What is a number in JavaScript?

A

Numeric Values

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

What is an arithmetic operator?

A

Operators can do math

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

Name four of the arithmetic operators?

A

+ (addition), - (subtraction), * (multiplication), / (division) %(remainder, modulus)

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

What is the order of execution?

A

By precedence - mult, div, comes first. Parenthesis overpowers everything.

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

What is a boolean?

A

data type that is true or false

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

What is a comparison operator?

A

> < and it returns a boolean

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

What is the difference between undefined and null?

A

undefined is an absence of a value, null is intentional absence of object value

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

What is a function?

A

group a series of statements together to perform a specific task

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

Why are functions useful?

A

reusable code

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

How do you call a function?

A

function name ( )

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

What are the parts of a function definition?

A

function keyword, function name, parameter, code block

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

What is the difference between a parameter and an argument?

A

declaring a function they are parameters and calling a function they are arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the difference between null and undefined?
Null is an object and undefined is undefined
26
Why do you always use === for comparisons?
Due to type coercion
27
Do all if statements require an else statement?
No
28
What is the proper syntax for using the or operator?
| |
29
What is the primary use case for switches?
Comparing a value to many values
30
Does the default case have to be at the bottom of the switch statement?
No it can jump back to the default
31
What happens if there is no break statement between cases?
It will continually run all cases even if it's met
32
What is an object in JavaScript?
Set of variables and functions / collection of related data
33
How do you create an object literal?
curly braces, and its contents
34
What is a property in relation to JavaScript objects?
variables
35
How do you remove a property from an object?
delete keyword object name and property
36
When should you use bracket notation over dot notation with objects?
variable that you need to substitute
37
What is an array in JavaScript?
list or set of values that are related to each other that are ordered.
38
How do you create an array literal?
[ ]
39
What are the keys for the values inside an array?
index number
40
Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?
objects
41
What is the primary advantage to storing your selected elements in a variable?
To be able to use it without selecting the elements again
42
Why might you need JavaScript to modify the DOM after the page loads?
better user experience and manipulate data without refreshing the page.
43
How can you better prepare when writing HTML for DOM manipulation in your JavaScript code?
class name, ID
44
What are the differences between innertext and textContent?
innerText gets only the text and not the elements that are hidden
45
What datatype are the values you remove from a text input?
String
46
Why is it so important to be able to dynamically update text?
A way to communicate with the user
47
What are some of the drawbacks of HTML Event Handler Attributes?
To keep HTML and Javascript separate
48
Why is the Window.event property to be avoided in new code?
Old technique
49
What is the difference between the getElementById() method and the querySelector() method?
QuerySelector chooses the first one that matches the argument
50
Who passes in the event object into the handleClick callback function?
JavaScript
51
Does a callback function require a name?
You can have anonymous but should always have a name
52
What is the purpose of a loop?
Reiterate through elements
53
Why might there be different kinds of loops?
While loops are better to have a value you are comparing. For loops are useful when you have a variable you want to increment
54
What is the purpose of a conditional expression as it relates to loops?
To let the loop know when to end or continue the loop
55
Could a loop potentially go on forever?
Yes if the expression is never found false.
56
Could a loop never start?
Yes. if the expression never results true
57
What potential use cases are there for for loops?
iterate through an array.
58
Which pieces of information provided in the parentheses for a for loop are mandatory?
nothing
59
What is a for in loop?
Iterates to property names in objects
60
How do you target the value of a property in an object.
bracket notation within that for in loop
61
When should you use a for in loop?
To debug
62
What is the difference between the parentNode and parentElement properties?
Selects just the note and the other selects the whole element
63
Why is it important to be able to traverse the DOM?
Be able to target elements directly
64
What are two ways to target elements on the DOM?
querySelector and getElementBy
65
What is another way to add a text node to an element other than using textContent.
createTextNode and appendChild
66
How do you create a HTML element using vanilla Javascript?
createElement()
67
Why is using loops and arrays for creating multiple dom elements preferable to creating them one at a time?
More efficient, instead of writing the same code every single time
68
Why are arrays preferred over objects for the functionality referenced in question 1?
Array is index and easy to loop over and keep one collection of data
69
Why is it important to be able to retrieve and use data from inputs?
To be able to store data
70
Why is it dangerous to assume you have the correct data when creating elements?
Because due to user error
71
What is jQuery?
File included in webpages that lets one find elements using css-style selectors
72
What is the jQuery selector function?
jquery() or $()
73
What does the jQuery selector function return?
Object
74
Why would someone use jQuery over vanilla Javascript?
selecting elements is simpler because it uses CSS style syntax cross browser made a selection and can apply multiple methods to it
75
What are some downsides from using jQuery over vanilla Javascript?
library is very large and has to parse
76
Why do we use the tag at the bottom of the body, instead of putting it inside the tag?
the way the document parses is from top to bottom
77
Why do we use the tag at the bottom of the body, instead of putting it inside the tag?
the way the document parses is from top to bottom
78
How do you get the text out of an HTML element?
.text method
79
How do you get the value out of an HTML input field?
.val method
80
What's the difference between .text() and .html()?
.text only returns the content from every element in the selection as opposed to .html returns the html inside the first element.
81
What does .on() do?
handle events
82
What does .on() do?
handle events
83
What is event bubbling?
starts the event that triggered the event and goes up to each parent.
84
Target and current target
Target - the element that triggered the event | currentTarget - what element was actually attached to the event handler
85
Target and current target
Target - the element that triggered the event | currentTarget - what element was actually attached to the event handler
86
What is the first argument the function setTimeout takes?
Function
87
If the second argument is not passed into the setTimeout function, what is the default value?
0 so immediately
88
What are some scenarios where setTimeout can be useful?
Modal to pop up,
89
What argument does the clearInterval function take?
ID that is returned by the set interval function
90
What does the term blocking mean?
Delaying the code to execute because the call stack is blocked
91
What is the call stack?
data structure - pushes and pops to the stack. arrangement of actions that need to be taken
92
What is the call stack?
data structure - pushes and pops to the stack. arrangement of actions that need to be taken
93
What is a modal?
overlay a small element over a website
94
What are some use cases for modals?
Overlays to advise for activity, information, approval
95
Why does a modal usually need to occupy the entire height and width of the viewport?
to not let the user evade it
96
What is this?
This is used to return values in the properties of the object
97
What does bind do?
method that sets the this keyword to the object passed in
98
What is the difference between a function and an object literal?
functions have 3 methods - apply, bind, call but are also objects still.
99
What is the first thing that happens in a class when it is instantiated with the new keyword?
Always first makes an empty object
100
Since classes are technically functions as well. Can you name a difference between classes and functions?
Use the new keyword
101
What is a static method?
attached to the creator