Day 33 - 7/10
Plan: Wait for confirmation from Ms Ly then move to javascript
Progress:
Output:
document.getElementById("demo") / document.getElementsByClassName("name")both ' ' and " " are accepted
document.getElementById("demo").innerHTML = ;: to write into an html elementdocument.write(5 + 6);: to write into html output; if used after html document is loaded will replace every existing html (example:onclick= "document.write(5 + 6)") (note: used only in testing)alert(5+6);: alert box to display dataconsole.log(5+6);: for debuggingwindow.print(): to open print window
Statements:
white spaces are ignored
max-line width should be 80 characters; best line-break point is after an operator
Syntax (or rules)
fixed value called Literals; variable value called Variables
identifier (or variable names) : start with letter, dollar sign ($) or an underscore ( _ ), not number; uppercase and lowercase are sensitive
hyphens ( - ) are not allowed
Variables
declare variables before use
letandconstare more used;letfor changable variables;constfor constant variables;varfor old browsersre-declare a variable will not make it lose its value; re-declare doesnt work with
letorconstafter a number in quotes, the rest of the numbers will be treated as string and no whitespace
( $ ) not common, often used as an alias for the main function
( _ ) not common, often used as an alias for "private (hidden)" variables
Let
in a { } block, variable declared with
varcan be accessed from outside, the rest cannot
Const
cannot redeclared; reassigned; have block scope
a variable declared inside and outside the block is not the same
Redeclaring an existing
varorletvariable toconst, in the same scope, is not allowedReassigning an existing
constvariable, in the same scope, is not allowed
Last updated