Fundamentals Flashcards
Assignment operators, string interpolation, variables, methods, etc.
What are assignment operators?
Assign a value to its left operand based on the value of its right operand.
+= addition assignment
-= subtraction assignment
*= multiplication assignment
/= division assignment
What is string interpolation?
Process of evaluating string literals containing one or more placeholders (expressions, variables, etc)
Performed using template literals like:Hi ${userName} welcome to the app
;
Performed using string concatenation like:
‘Hi ‘ + userName + ‘ welcome to the app’;
What are variables and how can you declare them?
Variables are used to store data in memory and ensure code re-usability. They are referenced by name.
Types: const, let, and previously var
What is a template literal?
Strings that allow embedded expressions. Use backticks instead of quotes.
let name = “Kristin”;
console.log(Hello, ${name}
);
console.log(Billy is ${6+8} years old.
);
let
creates a local variable that can be re-assigned
initialization is optional
will contain ‘undefined’ if nothing is assigned to it
const
creates a local variable that cannot be re-assigned
initialization is required
will throw a runtime error if not assigned
String Concatenation
Creates a new string by concatenating multiple other strings together using the addition+ operator
let welcomeMsg = ‘Hi ‘ + userName + ‘ welcome to the app’
console.log()
used to log or print messages, objects, and other information to the console
console.log(‘some important message’)
What are methods?
They return information about an object and are called by appending an instance with a period, the method name, and parentheses
Math.random(); //returns a number between 0 -1
undefined
a primitive JS value that represents lack of a defined value
null
a primitive JS data type that represents the intentional absence of a value
Arithmetic Operators
+ addition
- subtraction
* multiplication
/ division
% modulo - returns the number that remains after the right-hand number divides into the left-hand number as many times as it can