Strings & numbers in JavaScript Flashcards
What is concatenating?
Connecting two or more strings with the + operator in order to create a bigger string.
How would you include quotation marks within a string?
Use a \ backslash in order to escape the quotation mark delimiter:
const heSaid = "He said, \"Foo!\""; console.log(heSaid); // => He said, "Foo!"
What does \t do in a string?
It creates a tab between the strings.
What does \n do in a string?
It represents a new line.
How can you break up a very long string?
Use either the escape character () or by closing the quote, adding a + sign, and starting a new string on the next line.
How do you compare two strings together?
Connect them with the === operator like so:
const string1 = 'foo'; const string2 = 'foo'; const string3 = 'bar';
string1 === string2; // => true
string2 === string3; // => false
What are template strings?
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 many arithmetic operators are there, and what are they?
\+ addition - subtraction * multiplication / division ** exponentiation % remainder (also known as the "modulo" or "modulus" operator)
What is operator precedence?
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.
What are the different ways numbers can be compared with one another?
< less than <= less than or equal to > greater than >= greater than or equal to === equal !== not equal
What is the value based on this code?
let counter = 0; console.log(counter)
counter += 1;
console.log(counter)
Value is 1
What is the value based on this code?
let counter = 0; console.log(counter)
counter += 1;
console.log(counter)
counter += 9;
console.log(counter)
Value is 10
When you run the ++ either before or after a variable, it returns a value. What is the difference between before or after the variable?
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.