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 element

  • document.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 data

  • console.log(5+6); : for debugging

  • window.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

  • let and const are more used; let for changable variables; const for constant variables; var for old browsers

  • re-declare a variable will not make it lose its value; re-declare doesnt work with let or const

  • after 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 var can 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 var or let variable to const, in the same scope, is not allowed

  • Reassigning an existing const variable, in the same scope, is not allowed

Last updated