JavaScript Flashcards

(157 cards)

1
Q

What is the purpose of variables?

A

to hold data (numbers, strings, booleans)

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

How do you declare a variable?

A

by creating a 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

adding an equal sign next the variable name and then giving it a value/data

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 but we shouldn’t use 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

it means that the capitalization needs to be the same in order to call that variable (ex. var myName and var MyName is two different variables)

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

it holds the data type of letters and other characters

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

it holds the data type of numbers (integers, decimals, etc)

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

it holds the data type of one of two values, true or false

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

a 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

by assigning it to a 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

null is subject to change, there is nothing but it could change into something. while undefined is literally nothing

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 that you won’t get confused to what is being logged

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

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 two or more strings are added 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

used to add one value to another

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 and re-assigns a new value to a variable

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

What are objects used for?

A

to hold a set of variables that all link to one thing/object

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

What are object properties?

A

it tells us about the object, stores info ab the object (ex. name:, age:,)

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

Describe object literal notation.

A

an array of keys and values

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

using the delete operator

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

using a dot notation or bracket notation (ex. example.name, example[‘name’])

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 values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
values within brackets [ ] (ex. var colors = ['red', 'white', 'blue']
26
How are arrays different from "plain" objects?
arrays store actual variables in an index starting from 0
27
What number represents the first index of an array?
0
28
What is the length property of an array?
it shows the amount of variables inside of an array
29
How do you calculate the last index of an array?
by subtracting the length of an array by 1 (ex. var lastIndex = example.length -1;)
30
What is a function in JavaScript?
it is a "power" tool, it is used to run a sequence of code when it is called
31
Describe the parts of a function definition.
a function definition is the name used for that function so you have something to call it, also contains parameters (ex. function sayHello(name) {} )
32
Describe the parts of a function call.
you can call a function using the function definition and parenthesis (ex. sayHello('Tim') )
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call has the value inside(a parameter) the parenthesis while the function definition has a variable (argument) inside
34
What is the difference between a parameter and an argument?
a parameter is like a placeholder for the value like a variable, an argument has a value. when we define a function we declare a parameter, when we call a function we pass it arguments
35
Why are function parameters useful?
it's a placeholder so that we know what will come out as an argument
36
What two effects does a return statement have on the behavior of a function?
it produces a value for us to use and it prevents any more code in the function's code block to run
37
Why do we log things to the console?
so that we able to see what the code is producing
38
What is a method?
it is a function which is a property of an object
39
How is a method different from any other function?
methods are associated with objects while function just performs a task when called
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?
using the Math.floor() method
42
How do you generate a random number?
using the Math.random() method
43
How do you delete an element from an array?
using the slice() , pop(), shift() method
44
How do you append an element to an array?
using the push() method
45
How do you break a string up into an array?
using the split() method
46
Do string methods change the original string? How would you check if you weren't sure?
string methods doesn't change the original string. to double check you can log it to the console
47
Roughly how many string methods are there according to the MDN Web docs?
about 50
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?
about 40
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
53
What is the purpose of an if statement?
so that the code will only run if the requirements are met
54
Is else required in order to use an if statement?
no
55
Describe the syntax (structure) of an if statement.
if (x = y) { return 'yay; }
56
What are the three logical operators?
&&, ||, !
57
How do you compare two different expressions in the same condition?
by using a logical operator && or | |
58
What is the purpose of a loop?
to run code over and over until the outcome is false or when it is capped
59
What is the purpose of a condition expression in a loop?
to see if the expression is true or not so it knows when to stop
60
What does "iteration" mean in the context of loops?
a sequence of code run repeatidly
61
When does the condition expression of a while loop get evaluated?
after the initialization expression
62
When does the initialization expression of a for loop get evaluated?
after the incrementation in the final expression or at the beginning of the iteration if it is the first time
63
When does the condition expression of a for loop get evaluated?
before starting a new iteration
64
When does the final expression of a for loop get evaluated?
after the iteration of the loop
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?
goes up 1
67
How do you iterate through the keys of an object?
using for in loops
68
Why do we log things to the console?
it is a debugger, it helps inspect a certain element
69
What is a "model"?
a model is the looks and design of a document that is being put on a page from memory. models are made with objects
70
Which "document" is being referred to in the phrase Document Object Model?
the document that is in the script element
71
What is the word "object" referring to in the phrase Document Object Model?
the nodes
72
What is a DOM Tree?
a dom tree consists of multiple nodes each representing an text content, elements, attributes, etc.
73
Give two examples of document methods that retrieve a single element from the DOM.
document.querySelector() document.getElementById()
74
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll()
75
Why might you want to assign the return value of a DOM query to a variable?
it is easier to console log and console dir
76
What console method allows you to inspect the properties of a DOM element object?
console.dir()
77
Why would a