JavaScript Flashcards

(129 cards)

1
Q

What is the purpose of variables?

A

to be able to store and reference data

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

How do you declare a variable?

A

use the keyword var with its name

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

use =

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

anything but cannot start with a number or a be a keyword

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

capital letters are not the same as lowercase letters

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

to store words into javascript

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 counting and arithmetic

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 state yes or no within javascript

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

assign to

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

use the assign to and 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 empty on purpose. Undefined is nothing is defined (usually accident)

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 console can be organized and easier to read

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

Give five examples of JavaScript primitives.

A

String, Number, Boolean, Null, Underfined

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

a number

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

What is string concatenation?

A

combining strings

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

add 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

take the variable and update value

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

What are objects used for?

A

a box to keep related stuff together

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

What are object properties?

A

exclusive variables for an object

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

How do you remove a property from an object?

A

Use the delete operator (ex: delete person.firstName)

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

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

A

dot notation or with brackets

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

What is a function in JavaScript?

A

group of actions that are repeatable

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

Describe the parts of a function definition.

A

keyword function, function name, ( ) with parameaters if there are any, { }, return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe the parts of a function call.
the function name with ( ) including paramethers inside, if any
26
When comparing them side-by-side, what are the differences between a function call and a function definition?
definition has keyword function and { }, calling does not
27
What is the difference between a parameter and an argument?
parameter are a placeholder until arguments are sent in
28
Why are function parameters useful?
allows us to change the value of the variables being sent through the function
29
What two effects does a return statement have on the behavior of a function?
return stops function from running and returns the value to the outside of the function
30
What are arrays used for?
store a list of values (strings, numbers, boolean, objects)
31
Describe array literal notation.
var = [ ] using brackets
32
How are arrays different from "plain" objects?
arrays use an index while objects use keywords to organize data
33
What number represents the first index of an array?
0
34
What is the length property of an array?
the number of elements in the array
35
How do you calculate the last index of an array?
array.length - 1
36
Why do we log things to the console?
to follow the the code and for other developers to read
37
What is a method?
a function that is a proporty of an object
38
How is a method different from any other function?
syntax; with a method you must provide which object its connected to
39
How do you remove the last element from an array?
_____.pop()
40
How do you round a number down to the nearest integer?
Math.floor()
41
How do you generate a random number?
Math.random( )
42
How do you delete an element from an array?
splice( start_index , how_many , replace? )
43
How do you append an element to an array?
splice( start_index , how_many , replace? )
44
How do you break a string up into an array?
___.split( )
45
Do string methods change the original string? How would you check if you weren't sure?
No, try it out or read some documentation
46
Is the return value of a function or method useful in every situation?
It does not need to be utilized in every instance
47
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
48
Give 6 examples of comparison operators.
=== , !== , > , < , <= , >=
49
What data type do comparison expressions evaluate to?
boolean
50
What is the purpose of a loop?
check a condition, more than once
51
What is the purpose of a condition expression in a loop?
to make the code run or stop the code
52
What does "iteration" mean in the context of loops?
one cycle of the code block
53
When does the condition expression of a while loop get evaluated?
before the iteration
54
When does the initialization expression of a for loop get evaluated?
at the start of the loop
55
When does the condition expression of a for loop get evaluated?
before every iteration
56
When does the final expression of a for loop get evaluated?
after each iteration
57
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
58
What does the ++ increment operator do?
increase counter by 1
59
How do you iterate through the keys of an object?
for..in loop
60
What is the purpose of an if statement?
evealuates a condition, if true it will run
61
Is else required in order to use an if statement?
no
62
Describe the syntax (structure) of an if statement.
if (condition) { }
63
What are the three logical operators?
AND&& OR|| !NOT
64
How do you compare two different expressions in the same condition?
by comparing their result
65
What are the four components of "the Cascade".
1. Source Order 2. Inheritance 3. Specificity 4. Important
66
What does the term "source order" mean with respect to CSS?
the order that the css rules are writtin on a stylesheet
67
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?
with inheritance
68
List the three selector types in order of increasing specificity.
~
69
Why is using !important considered bad practice?
Since it is just a quick fix it is not a long term fix
70
What is the className property of element objects?
string containing value of the class attribute
71
How do you update the CSS class attribute of an element using JavaScript?
use the className
72
What is the textContent property of element objects?
reads any text as a string to add/delete/update
73
How do you update the text within an element using JavaScript?
assigning a value to textContent property (var ____ = __nod__.textContent)
74
Is the event parameter of an event listener callback always useful?
No, does not need to be utilized
75
Why is storing information about a program in variables better than only storing it in the DOM?
so we can store the data and reference it
76
Why do we log things to the console?
check data to conform assumptions
77
What is the purpose of events and event handling?
to handle something that happned on the we page
78
What do [ ] square brackets mean in function and method syntax documentation?
that they are optional
79
What method of element objects lets you set up a function to be called when a specific type of event occurs?
________.addEventListener
80
What is a callback function?
functions to be used in the future
81
What object is passed into an event listener callback when the event fires?
object about info about the event
82
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
property that references the html element being use in the event
83
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
handleClick is a function definition. While handleClick( ) is calling the function and the return value will be the argument
84
What does the new operator do?
1. Creates a blank, plain JavaScript object; 2. Links (sets the constructor of) the newly created object to another object by setting the other object as its parent prototype; 3. Passes the newly created object from Step 1 as the this context; 4. Returns this if the function doesn't return an object.
85
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
86
What does the instanceof operator do?
if an object is a prototype of a constructor fucntion
87
What kind of inheritance does the JavaScript programming language use?
prototype inheritance
88
How is it possible to call methods on strings, arrays, and numbers even though those methods don't actually exist on objects, arrays, and numbers?
prototypes allow us to base those on others objects
89
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
in the Object prototype
90
What is 'this' in JavaScript?
pointing to Object it is inside
91
What does it mean to say that this is an "implicit parameter"?
avalible in function code block even though it was never defined or given as a parameter
92
When is the value of 'this' determined in a function; call time/definition time?
call time
93
How can you tell what the value of this will be for a particular function or method definition?
cannot tell until method/function is called
94
How can you tell what the value of this is for a particular function or method call?
what is to the left of the .
95
How can you tell what the value of this is for a particular function or method call?
function definition stored as a property of an object
96
How can you tell the difference between a method definition and a method call?
definition has the keyword fucntion anf the { }. call has the ( ) at the end
97
Describe method definition syntax (structure).
definition has the keyword function anf the { }
98
Describe method call syntax (structure).
call has the ( ) at the end
99
How is a method different from any other function?
it is stored within an object as a property
100
What is the defining characteristic of Object-Oriented Programming?
objects can contain data (as properties) and behavior (as methods)
101
What are the four "principles" of Object-Oriented Programming?
1. Abstraction 2. Encapsulation 3. Iheritance 4. Polymorphism
102
What is "abstraction"?
turns a complex thing into something easy to use
103
What does API stand for?
applications programming interface
104
What is the purpose of an API?
give programmers a way to interact with the system in a simplified way
105
What event is fired when a user places their cursor in a form control?
focus
106
What event is fired when a user's cursor leaves a form control?
blur
107
What event is fired as a user changes the value of a form control?
input
108
What event is fired when a user clicks the "submit" button within a ?
submit
109
What does the event.preventDefault() method do?
prevent the page from reloading when form is submitted
110
What does submitting a form without event.preventDefault() do?
Reload page
111
What property of a form element object contains all of the form's controls.
_____.elements.___
112
What property of form a control object gets and sets its value?
.value
113
What is a "callback" function?
a function passes into another function as an argument
114
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
setTimeout( )
115
How can you set up a function to be called repeatedly without using a loop?
setInterval( )
116
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
117
What do setTimeout() and setInterval() return?
a unique ID that can be passed through clearInterval( ) to stop
118
What is AJAX?
a group of technologies that offer asynchronous functionality
119
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
120
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
121
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load event
122
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They share the event.target prototype
123
What is a client?
initiate request from server
124
What is a server?
provides a service (returns a response to client)
125
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
126
What three things are on the start-line of an HTTP request message?
1. HTTP Method 2. Request Target (url) 3. HTTP Version (usually 1.1)
127
What three things are on the start-line of an HTTP response message?
1. HTTP Version (1.1) 2. Status Code 3. Status Text (description of code)
128
What are HTTP headers?
Specify the request /describe the body included in the message
129
Is a body required for a valid HTTP request or response message?
body is optional