- HTML defines static elements for the website
- Understandable by web Browsers
- A dynamic computer programming language
- Most commonly for web pages on web browsers
- Most web pages are generated from HTML (HyperText Markup Language).
We are going to learn fundamentals, before we will learn more advanced libraries like JQuery in the future
The javascript prompt, aka “the Console” help 24 3.14
1 + 1
3 - 123
123 * 0.123
123 / 2
123 % 2 = 1
- recognize negative number as well (5+7) * 3 = 12 * 3 = 36 (-3 * 4) + 3 - 12 / 2
6 > 4 -> true
9 < 5 -> false
3 == 4 -> false
12 != 4 => true
8 >= -2 -> true
10 <= 10 -> true
- store and process ‘flat text’
- double quotation marks allows JS to recognize it as a string
“Hello World!”
“Hello” + “ “ + ”World!” “Hello World!”
“There are“ + 365 + “days in a year” “There are365days in a year” “There are 365 days in a year”
- expressions gets evaluated
“Platform “ + 9 + “ and “ + 3/4 “Platform 9 and 0.75” “Platform “ + 9 + “ and 3/4” “Platform 9 and 3/4”
\” -> “
\ ->
\t -> next tab
\n -> next line
Quoth the raven:
"Nevermore!"
“Harry” == “Harry” -> true “Harry” == “you” -> false “Harry” != “you” -> true
“Harry”.length = 5 “Harry Chen”.length = 10 -> include all spaces and notations
var apples = 3
- variable keyword
- variable name
- assignment operator
- value to be stored
apples -> 3
- no spaces in variable name
- no digit in front of variable name
- can have underscore
- can have number sign
var goodNameHere
- change variable content
apples = 4
- no var keyword needed
apples -> 4
var oranges = 3 var fruits = oranges + apples fruits -> 7 fruits += 3 -> 10 fruits = fruits * 2 => 20 fruits *= 2 -> 40
“There are ” + apples + “ apples!”
apples ++ oranges ——
var age = 10; var ageIn5Years = age+5;
var platform = “Platform 9 and 3/4” platform.length var first = “asdfasfsafasdfsadf” var second = “asdfasfa3fsadnsdfgfsdasdfsd” first.length > second.length
- a number “index” starting from 0
var myname = ‘Harry’ myname[0] myname.charAt(0) myname.length
- ‘index’ will always be 1 less than the length since it starts at 0
var trainsOperational = 8 var totalTrains = 12 var operatingStatus = “ trains are operation today.” trainsOperation + “ out of “ + total Trains + operatingStatus -> “8 out of 12 trains are operational today.” -> you can change variable, and the string will be automatically updated