Strings & numbers in JavaScript Flashcards

1
Q

What is concatenating?

A

Connecting two or more strings with the + operator in order to create a bigger string.

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

How would you include quotation marks within a string?

A

Use a \ backslash in order to escape the quotation mark delimiter:

const heSaid = "He said, \"Foo!\"";
console.log(heSaid); // => He said, "Foo!"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does \t do in a string?

A

It creates a tab between the strings.

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

What does \n do in a string?

A

It represents a new line.

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

How can you break up a very long string?

A

Use either the escape character () or by closing the quote, adding a + sign, and starting a new string on the next line.

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

How do you compare two strings together?

A

Connect them with the === operator like so:

const string1 = 'foo';
const string2 = 'foo';
const string3 = 'bar';

string1 === string2; // => true
string2 === string3; // => false

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

What are template strings?

A

They allow us to refer to variables and execute JavaScript code inside of a string. Template strings are indicated by surrounding text between opening and closing backticks (`). Inside a template string, you can refer to variables or execute code by using ${}.

const foo = 'foo';
function sayHello() {
  return 'hello ';
}

const myString = foo is set to ${foo}. Let's say hello: ${sayHello()};

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

How many arithmetic operators are there, and what are they?

A
\+ addition
- subtraction
* multiplication
/ division
** exponentiation
% remainder (also known as the "modulo" or "modulus" operator)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is operator precedence?

A

This is how JavaScript handles equations. It follows PEMDAS (parenthesis, exponents, multiplication/division, addition/subtraction).

For example, in let foo = 3 + 2 * 6 / 3

foo will evaluate to 7 because we first do 2 * 6 / 3, which gives us 4, and add that to 3, for 7.

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

What are the different ways numbers can be compared with one another?

A
< less than
<= less than or equal to
> greater than
>= greater than or equal to
=== equal
!== not equal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the value based on this code?

let counter = 0;
console.log(counter)

counter += 1;
console.log(counter)

A

Value is 1

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

What is the value based on this code?

let counter = 0;
console.log(counter)

counter += 1;
console.log(counter)

counter += 9;
console.log(counter)

A

Value is 10

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

When you run the ++ either before or after a variable, it returns a value. What is the difference between before or after the variable?

A

In the case of the prefix operator, it increments before it returns the value. In the case of the postfix operator, it increments after it returns the value.

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