JS Course 1: Fundamental 1 Flashcards

1
Q

How do you declare a variable? What are the three different ways to declare a variable? (and when to use which way)

A

You can declare a variable in 3 ways:

“let” is used to create a variable where the value of that variable can be reassigned or changed.

“const” is used to create a variable where the value of that variable cannot be reassigned or changed in anwyay.

“var” is an older way to declare variables in JavaScript.

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

What are the rules for naming variables

A

The name of the variable should be indicative to what the variable holds or is used for. It must be in camelCase. The first character cannot be a digit. And, the name must only contain letters or digits, but also can include $ and _

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

What are operators, operands and operations?

A

Operations are composed of operators and operands. All together, it creates a problem to be solved.

Operands are what are being affected by the operator(s)

Operators are what’s happening between the two operands in an operation.

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

What is concatenation and what happens when you add numbers and strings together?

A

When you add numbers and strings together, JavaScript recognizes the number as a string since we are working with a string. So, instead of adding the values of the numbers, let’s say “1” + 1, we get “11”. This is a string concatenation.

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

What are the different types of operators in JavaScript?

A

There are assignment operators that assign a value, arithmetic operators that determines what happens to an operand or operands, comparison operators that compares two operands, logical operators, and type operators.

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

How does the Modulo (%), or Remainder, operator work?

A

The modulo operator works by taking the right operand and divides it by the left operand. If it divides equally, the outcome is 0. If there is any remainder, that value is returned.

Example: 5 % 3

5 % 3, 3 goes into 5 once, the remainder after that is 2.

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

What are operator precedence values?

A

Operator precedence is a system JavaScript implements on operators similar to the concept of PEMDAS.

Some operators will come first, or take precedence over others, in an operation or operations.

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

What are the increment and decrement operators?

A

Increment ++ and Decrement – operators are used to symbolize a +1 or -1 in value.

Example:
let numberOne = 1;
numberOne++;
console.log(numberOne);

The outcome would be 2. If it were decremented, it’d be 0.

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

What is the difference between prefixing and postfixing increment or decrement operators?

A

Depending on the placement of an increment or decrement, the outcome will change.

Prefixing is for when you want to use the value after the operation.

Postfixing is for when you want to use the original value before the increment/decrement.

They both will still increment/decrement, just as different times.

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

What is the unary plus operator? What is the binary plus operator?

A

The unary plus operator refers to the plus sign (+) being put right next to a variable or value to, commonly, change a string to its number value. Example: +”10”

The binary plus operator is a plus sign (+) used between two operands.

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

When would you receive aNaNresult?

A

You would receive a NaN result when the value cannot be computed or as a result of attempted number coercion.

Example: Adding NaN with any number value.

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