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