JS 1 Flashcards

(65 cards)

1
Q

What is the purpose of variables?

A

variables are assigned data, and allow for referring to them later to access that 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

“var” or “let” keyword followed by the 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

variable name, equal sign, followed by value assigned

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

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

case (lowercase/uppercase) needs to be exact, since they are differentiated in javascript

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

a string is made up of characters in a row and is used to store text

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

a number is for numeric value and used in mathematical operations

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

booleans allow for the ability to make decisions based on 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

the assignment operator allows for assigning a value 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

variable name, then equal sign, followed by 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 assigned to a variable which should be purposefully empty for now
  • undefined is accidentally empty, assigned by computer when no value is provided
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 to know where the information is coming from, helps other developers

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

combining strings with the plus operator

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 numbers or combining strings (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 result of the right side plus the left side and replaces the left side

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

What are objects used for?

A

store key/value collections of data, as well as methods relevant to that object

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

What are object properties?

A

the association between a key and a value, or the equivalent of a variable stored in an object

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

Describe object literal notation.

A

a way to initialize an object using the left curly brace and right curly brace, with optional properties nested inside

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 operator to remove the property completely

- assign to empty string to remove the value only

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 notation: object name, dot, property key

- bracket notation: object name, brackets enclosing quotation marks enclosing property key

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

What are arrays used for?

A

arrays store lists of information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
square brackets surrounding the data strings
26
How are arrays different from "plain" objects?
arrays are ordered by number, objects have property names
27
What number represents the first index of an array?
zero
28
What is the length property of an array?
number of elements in an array
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
a reusable container of code which performs actions
31
Describe the parts of a function definition.
function keyword, function name, parameters surrounded by parenthesis, code block, optional return statement
32
Describe the parts of a function call.
function name, arguments surrounded by parenthesis
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition is the creation/declaration of the function with a function keyword and code block, while a function call is running/invoking an already created function.
34
What is the difference between a parameter and an argument?
A parameter takes in arguments. Parameters are placeholders in a function's definition, while arguments are values used in a function's call.
35
Why are function parameters useful?
Parameters allow for performing actions on different data of the same type when the function is invoked multiple times.
36
What two effects does a return statement have on the behavior of a function?
a return statement exits the code block and allows the called function to evaluate to the returned value
37
Why do we log things to the console?
to see an output to help debugging in development
38
What is a method?
a function in an object
39
How is a method different from any other function?
a method is specific to an object, so have to specify object name with method
40
How do you remove the last element from an array?
.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 with first arg being index and second arg being number of items to remove
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 with argument being what character(s) you want to split with
46
Do string methods change the original string? How would you check if you weren't sure?
No, MDN documentation
47
Is the return value of a function or method useful in every situation?
not always
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.
``` < Less than operator. > Greater than operator. <= Less than or equal operator. >= Greater than or equal operator. !== strict inequality operator === strict equality operator ```
50
What data type do comparison expressions evaluate?
boolean
51
What is the purpose of an if statement?
check a condition to make choices
52
Is 'else' required in order to use an if statement?
no
53
Describe the syntax (structure) of an if statement.
if keyword, then condition in parenthesis, then body in curly braces
54
What are the three logical operators?
&& and operator || or operator ! not operator
55
How do you compare two different expressions in the same condition?
use logical operators (&&, ||) in between the expressions
56
What is the purpose of a loop?
repetition
57
What is the purpose of a condition expression in a loop?
to see if the loop should stop
58
What does "iteration" mean in the context of loops?
an instance of repeating the code block
59
When does the condition expression of a while loop get evaluated?
before the while loop body runs
60
When does the initialization expression of a for loop get evaluated?
first
61
When does the condition expression of a for loop get evaluated?
after initialization, but before code block runs
62
When does the final expression of a for loop get evaluated?
at the end of each iteration
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break keyword
64
What does the ++ increment operator do?
increases value of operand by 1
65
How do you iterate through the keys of an object?
for / in loop