JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Storing values

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 the var keyword

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

Var x = 89;

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

Underscores, $. Numbers and letters

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

The uppercase or lowercase letter refers to different values

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 or manipulate text letters and sentences

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 and manipulate numbers and decimals

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

True or false for conditionals, loops

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

Assigning a value to a variables

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 variable name and the equal sign and assign the 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 an intentional no value, and undefined is not intentional

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

For clarity to understanding what the console is working on, point of reference

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 numbers boolean null undefined

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

numeric, numbers

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

What is string concatenation?

A

adding strings together

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 numbers and concatenating strings

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

adding to the value of the variables

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

What are objects used for?

A

Containers for keeping information

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

What are object properties?

A

The keys that give information about the object

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

Describe object literal notation.

A

{} property: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 keyword

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

[] or dot notation

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

What are arrays used for?

A

to store multiple items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
[] separated by ","
26
How are arrays different from "plain" objects?
it can be indexed by numbers starting from 0
27
What number represents the first index of an array?
0
28
What is the length property of an array?
calculate the size of the array
29
How do you calculate the last index of an array?
length -1
30
What is a function in JavaScript?
A process that can be used and called to perform that same process.
31
Describe the parts of a function definition.
The name of the function, the function keyword, parameter list., code block, return statement.
32
Describe the parts of a function call.
Name of the function () arguments in the parenthesis.
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function calls require actual values, while function definitions require a name or variables, and function keyword.
34
What is the difference between a parameter and an argument?
Parameters are the name that is given o the piece of data that will give, later on, arguments are the actual values that are being passed on to the function.
35
Why are function parameters useful?
To be empty conatainers to hold values for the upcoming values
36
What two effects does a return statement have on the behavior of a function?
It makes the value of the function a value that is not undefined.
37
Why do we log things to the console?
Debugging and for clarity.
38
What is a method?
A function that is being stored as a property.
39
How is a method different from any other function?
A method must be attached and be called upon an object.
40
How do you remove the last element from an array?
array.pop()
41
How do you round a number down to the nearest integer?
Math.floor()
42
How do you generate a random number?
Math.random() within the range of 0-1 non-inclusive
43
How do you delete an element from an array?
array.shift()-> from the begining;array.pop -> from the end; array.splice() froman arbitrary point till any point.
44
How do you append an element to an array?
srting.push()
45
How do you break a string up into an array?
string.split()
46
Do string methods change the original string? How would you check if you weren't sure?
No, because strings are immutable-> log console and mdn.
47
Roughly how many string methods are there according to the MDN Web docs?
A lot.
48
Is the return value of a function or method useful in every situation?
No,
49
Roughly how many array methods are there according to the MDN Web docs?
A lot
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
Give 6 examples of comparison operators.
>,=,+===,!==
52
What data type do comparison expressions evaluate to?
boolean (true or false)
53
What is the purpose of an if statement?
Change the flow of the code, and make decisions.
54
Is else required in order to use an if statement?
No
55
Describe the syntax (structure) of an if statement.
If (condition){}
56
What are the three logical operators?
logical and, or, not
57
How do you compare two different expressions in the same condition?
&& or/and ||
58
What is the purpose of a loop?
To allow to do something multiple times
59
What is the purpose of a condition expression in a loop?
To put a stop to the loop
60
What does "iteration" mean in the context of loops?
Running of the for loop code block
61
When does the condition expression of a while loop get evaluated?
Beginning and after each iteration
62
When does the initialization expression of a for loop get evaluated?
In the beginning, and it only happens one time
63
When does the condition expression of a for loop get evaluated?
Before each iteration
64
When does the final expression of a for loop get evaluated?
After the code block
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
66
What does the ++ increment operator do?
Increments the counter variable
67
How do you iterate through the keys of an object?
For in loop
68
What event is fired when a user places their cursor in a form control?
focus
69
What event is fired when a user's cursor leaves a form control?
blur
70
What event is fired as a user changes the value of a form control?
input
71
What event is fired when a user clicks the "submit" button within a ?
submit
72
What does the event.preventDefault() method do?
prevent the default state from occurring
73
What does submitting a form without event.preventDefault() do?
delete the data
74
What property of a form element object contains all of the form's controls.
.elements property
75
What property of form a control object gets and sets its value?
value property
76
What is one risk of writing a lot of code without checking to see if it works so far?
the code could be broken but you wouldn't know where.
77
What is an advantage of having your console open when writing a JavaScript program?
visualize code and variables
78
What is a method?
A function of the object
79
How can you tell the difference between a method definition and a method call?
the function definition() block and call: name of the object. method name ().
80
Describe method definition syntax (structure).
Methods are functions attached to object,
81
Describe a method call syntax (structure).
object.methodname(arguments).
82
How is a method different from any other function?
that it acts on the object
83
What is the defining characteristic of Object-Oriented Programming?
Objects contain data and behavior.
84
What are the four "principles" of Object-Oriented Programming?
encapsulation, polymorphism, abstraction, inheritance
85
What is "abstraction"?
hiding irrelevant information
86
What does API stand for?
application programming interface
87
What is the purpose of an API?
allows the application to access data to communicate to the user and vice versa
88
What is* this* in JavaScript?
Object that the function is acting on
89
What does it mean to say that *this* is an "implicit parameter"?
it is actaully named and typed out
90
When is the value of *this* determined in a function; call time or definition time?
Call time
91
``` What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } }; ```
Nothing at this point
92
Given the above character object, what is the result of the following code snippet? Why? character.greet();
It's a me Mario!
93
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
It's a-me undefined
94
How can you tell what the value of this will be for a particular function or method definition?
You can't, as it hasn't been called yet.
95
How can you tell what the value of this is for a particular function or method call?
Object to the left of the dot.