JavaScript Flashcards

1
Q

What is the purpose of variables?

A

The purpose of variables is to store a value.

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

How do you declare a variable?

A

A variable is declared with the const, var, or let keyword along with a name. e.g. ‘var test’.

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

To initialize a variable you use the = operator. e.g. ‘var test = ‘test’ ‘.

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

The characters used must be a letter, underscore, or $.

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

Variables are distinguished by their capitalization. e.g. ‘var Test’ and var test’ are 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

A string is used to store a sequence of 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

A number is used to store numeric values.

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

A boolean is used to store a true/false value.

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 = operator is the assignment operator. It assign 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

To update a variable you call the variable along with a new value. e.g. ‘test = ‘hi’.

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

The Null type is purposely defined, while undefined is typically accidental.

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

Adding labels to console log makes it easier to distinguish where the value is coming from.

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

Give five examples of JavaScript primitives.

A

The JavaScript primitives are: Number, String, Boolean, undefined, BigInt, and Symbol.

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 data is returned by an arithmetic operation.

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

What is string concatenation?

A

String concatenation is joining strings by using the + operator. e.g. ‘var test = ‘hi ‘ + ‘name’ will return ‘hi name’.

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

The + operator is used for concatenation along with addition.

17
Q

What data type is returned by comparing two values (, ===, etc)?

A

The data type returned by comparison operators is a boolean. e.g. true/false

18
Q

What does the += “plus-equals” operator do?

A
The += operator adds both sides of an assignment together before assigning. e.g. var test = 1, var hello = 1
test += hello is now equal to '2'.
19
Q

What are objects used for?

A

Objects are used to store multiple values.

20
Q

What are object properties?

A

Object properties are the names of their values. e.g. ‘number: 2’.

21
Q

Describe object literal notation.

A

A variable declaration followed by an object literal its containing properties, that are separated by commas, and a closing literal. e.g. var object = { property: ‘value’ }

22
Q

How do you remove a property from an object?

A

To remove a property from an object the ‘delete’ operator would be used. e.g. ‘delete object.property’.

23
Q

What are the two ways to get or update the value of a property?

A

To get/update a property you can use either bracket or dot notation. e.g. object.property or object[‘property’].

24
Q

What are arrays used for?

A

Arrays are used to store multiple values.

25
Q

Describe array literal notation.

A

A variable declaration followed by an array literal its containing properties, that are separated by commas, and a closing literal. e.g. var array = [ ‘value’ ]

26
Q

How are arrays different from “plain” objects?

A

Arrays store multiple values without property names.

27
Q

What number represents the first index of an array?

A

The first index of an array is [0]. The first value is stored in ‘0’ not ‘1’.

28
Q

What is the length property of an array?

A

The length property is the number of values stored within the array.

29
Q

How do you calculate the last index of an array?

A

To find the last index of an array you would use ‘array.length - 1’ as the index starts with 0 not 1.

30
Q

What is a function in JavaScript?

A

A function is a code block designed for a certain task that can be repeatedly used with different inputs.

31
Q

Describe the parts of a function definition.

A

A function definition consists of the function keyword followed by an optional name, a comma separated list of zero or more parameters surrounded by parentheses, the opening code block using ‘{‘, an optional return statement, and the ending block ‘}’.

32
Q

Describe the parts of a function call.

A

A function call consists of the function’s name and arguments to input.

33
Q

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

A function definition needs the function keyword and placeholder parameter names. A function call needs just the function name and the input rather than parameters.

34
Q

What is the difference between a parameter and an argument?

A

A Parameter is a placeholder for a value. An argument is that said value.

35
Q

Why are function parameters useful?

A

Parameters allow easy access to the inputted value via its name.

36
Q

What two effects does a return statement have on the behavior of a function?

A

A return statement will exit the code block and not continue while also outputting a value.