JavaScript Flashcards

(247 cards)

1
Q

What is the purpose of variables?

A

Purpose of variables is to store data/information.

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

How do you declare a variable?

A

Declaring a variable you need the variable keyword: var and giving it a name: variable 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

You assign a value by using the assignment operator: ‘=‘

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

Characters allowed in the variable names are letters, dollar sign, and underscore

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

When variables are “case sensitive” the same named variable is different when one of the words are capitalized.

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

Purpose of a string is to add new content into a page.

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

Purpose of a number is calculating, determining the size of the screen, moving the position of an element, or setting the amount of time an element should take to fade in.

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

Purpose of a boolean is to determine which part of a script should run.

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

“=“ means the value is being assigned to a variable

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 use the same variable and assign it to the new 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

undefined is a variable that hasn’t been defined to anything and null is a variable that is intentionally missing a value.

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

Labels can help us with what we’re referring to specific variables/values.

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

Give five examples of JavaScript primitives.

A

5 primitives: null, undefined, string, boolean, number

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

When you’re joining multiple strings into 1 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

Adding values and concatenation 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

It adds the value to a variable and then assigns the result to the variable

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

What are objects used for?

A

Objects are used to store/group data

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

What are object properties?

A

Object properties are variables associated with the object

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

Describe object literal notation.

A

Object Literal Notation consists of the variable object with properties and methods, and in the properties consists of keys and values, methods consists of functions.

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

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

dot or bracket notations

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

What is a function in JavaScript?

A

Its a set a statements that perform a task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe the parts of a function definition.
function keyword, name of the function, parameter, and curly braces
26
Describe the parts of a function call.
function name and parenthesis
27
When comparing them side-by-side, what are the differences between a function call and a function definition?
definition uses parameters and has a function code block call uses arguments to pass in
28
What is the difference between a parameter and an argument?
Parameters stores variables that can be used later and is used in a function definition argument is used in a function call
29
Why are function parameters useful?
You pass in different arguments in the parameters
30
What two effects does a return statement have on the behavior of a function?
It stops the code from running it will returns any value in the code block
31
Why do we log things to the console?
It tells us what the code is doing
32
What is a method?
Method is a property of an object that has a function definition
33
How is a method different from any other function?
Methods are assigned with an object property, while a function is not
34
How do you remove the last element from an array?
pop() method
35
How do you round a number down to the nearest integer?
floor() method
36
How do you generate a random number?
random() method
37
How do you delete an element from an array?
shift() method, pop() method, or splice() method
38
How do you append an element to an array?
push() method, or unshift() method
39
How do you break a string up into an array?
split() method
40
Do string methods change the original string? How would you check if you weren't sure?
Does not change. console.log() to check
41
Roughly how many string methods are there according to the MDN Web docs?
Roughly 50 string methods
42
Is the return value of a function or method useful in every situation?
No
43
Roughly how many array methods are there according to the MDN Web docs?
Roughly 40 array methods
44
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
45
Give 6 examples of comparison operators.
6 comparison operator: equal (=), not equal (!=), strictly equal (===), strictly not equal (!===), greater than (>), greater than or equal (>=), less than (<), less than or equal (<=).
46
What data type do comparison expressions evaluate to?
Boolean
47
What is the purpose of an if statement?
It is to run the code if the condition is met
48
Is else required in order to use an if statement?
No
49
Describe the syntax (structure) of an if statement.
if (condition) { statement } else { statement }
50
What are the three logical operators?
logical AND (&&), logical OR (| |), logical NOT (!)
51
How do you compare two different expressions in the same condition?
Compare two expressions with the logical operator
52
What is the purpose of a loop?
Its to repeat a task a set number of times.
53
What is the purpose of a condition expression in a loop?
To cause a loop to end.
54
What does "iteration" mean in the context of loops?
It is when the condition passes in the loop.
55
When does the condition expression of a while loop get evaluated?
Before executing the statement
56
When does the initialization expression of a for loop get evaluated?
The beginning of the loop
57
When does the condition expression of a for loop get evaluated?
Before each loop iteration
58
When does the final expression of a for loop get evaluated?
At the end of each loop interation
59
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
When the condition expression evaluates to false
60
What does the ++ increment operator do?
It adds one to variable in the initial conditional expression
61
How do you iterate through the keys of an object?
for ... in loop
62
Why do we log things to the console?
It tells us what the code is doing
63
What is a "model"?
The model is the DOM tree made up of objects. Any representation of the DOM.
64
Which "document" is being referred to in the phrase Document Object Model?
The document is the webpage; it can be displayed in the browser or the HTML source.
65
What is the word "object" referring to in the phrase Document Object Model?
“object” refers to the object of the document.
66
What is a DOM Tree?
DOM Tree is a model of a web page.
67
Give two examples of document methods that retrieve a single element from the DOM.
To get individual nodes, you use getElementById() or querySelector.
68
Give one example of a document method that retrieves multiple elements from the DOM at once.
To get multiple elements at once, you use getElementByClassName() - returns an HTML collection, getElementsByTagName(), or querySelectorAll() - returns a static NodeList.
69
Why might you want to assign the return value of a DOM query to a variable?
Because you might work with an element more than once.
70
What console method allows you to inspect the properties of a DOM element object?
console.dir()
71
Why would a