For a function to appear in the console on the chrome page (= building a bridge between the script in
VSC and the side that lives in the browser).
console.log
To check the type of data type:
console.log(typeof nameOfTheVariable);
// comment out of the code. /*
Comment out
Multi line
comments:
*/
When you create/declare a new variable:
let javascriptIsFun = true;
Declare two variables at the same time:
let x, y; = x and y are undefined.
When you want to change the value of the variable:
javascriptIsFun = 'YES!';
Template Strings
const anna = `I'm ${firstName}, a ${year - birthYear} years old $
{job}!`;
Multiple line Strings
console.log(`String
multiple
lines`);
Emojis: windows + period sign
IF / ELSE STATEMENTS – CONTROL STRUCTURE
if (age >= 18) {
console.log(`Sarah can start driving license 🙌`)
} else {
const yearsLeft = 18 - age;
console.log(`Sarah is too young. Wait another ${yearsLeft} years
:)`)
TYPE CONVERSION
TYPE COERCION
A value is a piece of data.
It's the most fundamental unit of information that we have in programming. Smallest unit of
information that we have in JS.
We can store values in variables.
Naming variables: camelCase.
Whenever you have multiple words in a variable name, write the first word with a lowercase and then
all the next words with upper case.
firstName
firstNamePerson
- Variable names cannot start with a number.
- Variable names cannot start with an upper-case letter!
- Variables written in all upper case means that is a constant value (real constant) that will never
change:
PI = 3.1416
- Variable names can only contain numbers (not at the beginning), letters, underscores, or the
dollar sign.
let -> declare variables that can change later (during the execution of our program)
mutate the variable = change a variable
*It is used when we declare empty variables.
const -> not supposed to change at any point in the future. It cannot be changed.
*We cannot declare an empty const.
const birthyear = 1998
var -> needs to be avoided.
Some operators have left-right precedence:
x = y = 25 - 10 - 5;
console.log(x, y);
We get: 10 10
TYPE CONVERSION is when we manually convert from one type to another.
TYPE COERCION is when JS automatically converts types behind the scenes from us.
ASSIGNMENT OPERATORS
let x = 10 + 5; (15)
x += 10; (x = x + 10 = 25)
x *= 4; (x = x * 4 = 100)
x ++; (x = x + 1)
x --; (x = x - 1)
COMPARISON OPERATORS
console.log(ageAnna > ageHao); (FALSE)
console.log(ageAnna >= 18); (TRUE)
TEMPLATE STRINGS
ONE LINE:
const anna = `I'm ${firstName}, a ${year - birthYear} years old $
{job}!`;
MULTIPLE LINES:
1. console.log(`String
2. multiple
3. lines`);