JavaScript Basics Flashcards

1
Q

What is the purpose of variables?

A

To store and re-use 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

Using the var, const, or let keyword followed by the name of the variable

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

How do you initialize (assign value to) a variable?

A

Using the var, const, or let keyword followed by the name of the variable followed by an assignment operator followed by a value

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, period, underscore, dollar sign

The first character of a variable name cannot be a number

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

What doesit mean to say that variable names are “case sensitive”?

A

You can only use the exact matching name of a variable as a value for anything

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

Allows you to create strings 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

It allows you to hold numeric value and perform calculations

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 use True or False values, such as conditionals

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

It’s the assignment operator

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

Without declaring the variable, assign the variable 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

Undefined means a value does not exist

Null is an assigned value that was used intentionally

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

It makes debugging easier when you know the value of what variable the console.log is returning

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

Numeric value

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

What is string concatenation?

A

Combining two or more string values

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

It either adds numbers or concatenates strings

17
Q

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

A

Boolean, True or False

18
Q

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

A

It adds (or concatenates) the current variable and a value, then assigns the result to the variable

19
Q

What are objects used for?

A

Objects group together a set of variables and functions to create a model of something you would recognize from the real world

20
Q

What ar eobject properties?

A

Object properties are variables

Properties can be functions, referred to as Methods

21
Q

Describe object literal notation

A

An object is a set of opening and closing curly braces and their content, known as key value pairs

Key value pairs need to be separated by a colon, and end in a comma (Unless it’s the last key value pair of the object)

22
Q

How do you remove a property from an object?

A

Using the delete operator before the dot notation or bracket notation for the object.property

23
Q

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

A

Using dot notation or bracket notation for the object property

To update, use the assignment operator before the new value

24
Q

What are arrays used for?

A

To hold related value as a list

25
Describe array literal notation
Square brackets containing items items are separated by a comma unless it's the last index of the array
26
How are arrays different from "plain" objects?
Arrays can be indexed numerically To get or update a value in the array, you have to use a numerical index
27
What number represents the first index of an array?
0
28
What is the length property of an array?
The length property returns the total number of values 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 block of reusable code that we can use as needed
31
Describe the parts of a function definition
Using the function keyword followed by an optional name and a pair of parentheses, which contains optional parameters After the parentheses, you have a pair of curly braces for the definition block
32
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function call will not have the function keyword nor a pair of curly braces for the definition block
33
Describe the parts of a function call
You call a function by using the functions name followed by a set of parentheses to pass arguments
34
What is the difference between a parameter and an argument?
A parameter is a placeholder for arguments while defining the definition An argument is a value being passed while calling the definition
35
Why are function parameters useful?
Parameters allow you to store data and use their value in the definition block to return a result
36
What two effects does a return statement have on the behavior of a function?
A return will return a value and it will break the function, not allowing any code after the return value to execute