Javascript Flashcards

(65 cards)

1
Q

What is the purpose of variables?

A

Used to hold data for scripting

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 then the name you want to give to the variable

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

with the “=” 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, 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

var Apple is different then var apple

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

Strings hold information in text form.

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

numbers hold information in numerical form.
Used 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 declare if something is true or false. Used for conditionals
Allow us to make decisions in code.

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

Is being assigned 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

write the name of the variable with a different 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 purposeful emptiness. (declared by developer)
undefined is accidental emptiness. (declared by javascript)

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

Helps with debugging.

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, 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

number

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

What is string concatenation?

A

To join 2 or more 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

can be used for arithmetic expressions and also string 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

adds the value and assigns that result to original value.
ex: x+=y // x = x + y

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

What are objects used for?

A

to store data with multiple properties(pieces of data) in a variable.

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

What are object properties?

A

individual piece of named data within an object.

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

Describe object literal notation.

A

declare the variable name it, “{
and key: value,
key: value,
};
object, key, 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

use the delete keyword followed by the object name and property name
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

object.property = ‘updated value’
object[‘property’] = ‘updated value’
dot notation and square bracket notation.

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

What are arrays used for?

A

It is used to store a list of information/values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
array = [ 'one', 'two', 'three'];
26
How are arrays different from "plain" objects?
Values of an array are almost always the exact same data type. Has a length property as default.
27
What number represents the first index of an array?
[0]
28
What is the length property of an array?
shows total number of values are in the array.
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
A process or set of actions with a name that can be reused within your code.
31
Describe the parts of a function definition.
(function keyword) ->function nameOfFunction(parameter) { function block ends with return statement };
32
Describe the parts of a function call.
nameOfFunction(argument); <-- argument is optional depending.
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definitions include a function keyword and code block.
34
What is the difference between a parameter and an argument?
parameter is used as a placeholder to define function, argument is the actual value used when you call it.
35
Why are function parameters useful?
It gives you the ability to apply the function to many different things without writing a different function.
36
What two effects does a return statement have on the behavior of a function?
1. return causes the function to produce a value. 2. Prevents any more code in the function code block from running.
37
Why do we log things to the console?
To help with troubleshooting, to check your code.
38
What is a method?
It is a function stored as a property of an object.
39
How is a method different from any other function?
It has a dot notation.
40
How do you remove the last element from an array?
Using the pop() method
41
How do you round a number down to the nearest integer?
Math.floor() method
42
How do you generate a random number?
Math.random() method
43
How do you delete an element from an array?
splice() method splice(start, delete)
44
How do you append an element to an array?
push() method
45
How do you break a string up into an array?
split() method
46
Do string methods change the original string? How would you check if you weren't sure?
They do not, use console.log method on original string to verify
47
Is the return value of a function or method useful in every situation?
No
48
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
49
Give 6 examples of comparison operators.
< > <= >= != == === !==
50
What data type do comparison expressions evaluate to?
Boolean
51
What is the purpose of an if statement?
Evaluate a condition to return a boolean and run instructions based on the boolean. It allows us to make decisions in our code.
52
Is else statement required in order to use an if statement?
No
53
Describe the syntax (structure) of an if statement.
if { is true { do this } }
54
What are the three logical operators?
"&& || ! (and, or, not)"
55
How do you compare two different expressions in the same condition?
"use && ||"
56
What is the purpose of a loop?
Loops allow an easy way to do something over and over.
57
What is the purpose of a condition expression in a loop?
Condition's ultimate goal is to check if the loop should move forward. Ultimate goal is to stop the loop.
58
What does "iteration" mean in the context of loops?
A single repetition of the code block.
59
When does the condition expression of a while loop get evaluated?
Evaluated before each loop iteration. (iteration of the code block)
60
When does the initialization expression of a for loop get evaluated?
Declared before the loop begins. Only runs one time.
61
When does the condition expression of a for loop get evaluated?
Evaluated before each loop iteration.
62
When does the final expression of a for loop get evaluated?
After each iteration and before the condition
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
64
What does the ++ increment operator do?
adds +1 to the value permanently.
65
How do you iterate through the keys of an object?
Use for for in loop.