JS
Why JS? π
I love that π
Learning path πΊ
π©
1. Introduction
π©
2. Control flow
π©
3. Functions
π©
4. Arrays
π©
5. Objects
π©
6. DOM
Primitives
// 1) Numbers
4
8.5
-3
// 2) Strings
"Hello, World!"
"815334455292"
// 3) Booleans
true
false
// 4) null
null
// 5) undefined
undefined
πͺπ»
// .1
200 % 3
// 2.
("Hello, " + "World!")[6]
// 3.
"hello".length % "world".length
Variables π¦
Variables are containers that store values
2 choices βπ»
1. Do you have values that you don't want changed or that will never change? Like the value of mathematical pi, they can be assigned to constΒ in javascript.
2. With let, we can re-assign the value.
null & undefined π¬
They will discuss laterΒ
console.log
alert
promp
<!DOCTYPE html>
<html>
<head>...</head>
<body>
...
<script>
console.log('Give me pizza π');
<script>
</body>
</html>
Code JS in a Separate File
console.log('Give me pizza π');
index.html
pizza.js
<!DOCTYPE html>
<html>
<head>...</head>
<body>
...
<script src="./pizza.js"></script>
</body>
</html>
Greet Exercise π
- Ask user's first name
- Ask user's last name
- Say Hello by calling user's full name
- Ask user's first name
- Ask user's last name
- Say Hello by calling user's full name
Pizza Exercise π
- Ask user's budget
- Say How many pizzas can a user buy?
Boolean Logic
Operator | Name | Example | βResult |
---|---|---|---|
> | Greater than | x > 10 | false |
>= | Greater than or equal to | x >= 5 | true |
< | Less than | x < -50 | false |
<= | Less than or equal to | x <= 100 | true |
== | Equal to | x == "5" | true |
!= | Not equal to | x != "b" | true |
=== | Equal value and type | x === "5" | false |
!== | Not equal value or equal type | x !== "5" | true |
Comparison Operators
x = 5
Logical Operators
AND, OR, and NOT
Operator | Name | Example | Result |
---|---|---|---|
&& | AND | x < 10 && x !== 5 | false |
|| | OR | y > 9 || x === 5 | true |
! | NOT | !(x === y) | true |
Exercise 1
const x = 10;
const y = "a"
y === "b" || x >= 10
Exercise 2
const x = 3;
const y = 8;
!(x == "3" || x === y) && !(y != 8 && x <= y)
Truthy and Falsy
Values that aren't actually true or false, are still inherently "truthy" or "falsey" when evaluated in a boolean context
!"Hello World"
!""
!null
!0
!-1
!NaN
JS
By Ali Montajebi
JS
- 383