JS Fundamentals Flashcards
To declare a variable
Use var, let, const
=
Assignment Operator
Another word for the starting value of a variable
The variable is initialized with [blank]
mathematical assignment operators
+=, -=, *=, /=
perform a mathematical operation to the variable, then reassign that value to the variable
ex: z += 1 is the same as z = z + 1
Increment and Decrement Operator
++, –
another mathematical assignment operator
the variable’s value is updated and assigned as the new value of that variable
increment operator - increases the value of the variable by 1
decrement operator - decreases the value of the variable by 1
ex:
let a = 10;
a++; // => a = 11;
String Interpolation
interpolate (or insert) variables into strings using template literals ex: const myPet = 'armadillo'; console.log(`I own a pet ${myPet}.`); - template literal is wrapped by backticks - Inside the template literal, you'll see a placeholder, ${myPet}. The value of myPet is inserted into the template literal - When we interpolate `I own a pet ${myPet}.`, the output we print is the string: 'I own a pet armadillo.' Using template literals, you can more easily tell what the new string will be. You also don't have to worry about escaping double quotes or single quotes.
typeof operator
checks the value to its right and returns, or passes back, a string of the data type
ex: const unknown1 = ‘foo’;
console. log(typeof unknown1); // Output: string
Conditional Statements
checks specific condition(s) and performs a task based on the condition(s)
if and if/else statements
Comparison Operators
operators to compare values
>, =, <=, ===, !==
evaluate to either true or false
Logical Operators
&&, ||