Class Six Notes
Intro to JavaScript
Intro and notes from lecture
- JS is a real-time complied language, that can be used in both brower and non-browser environments.
- datetypes: strings, numbers, boolean
Basic Output and some Functions
- can be programmed in a notepad or IDE, can be embedded or included in an HTML file
- function 1: ‘alert’ to display texts
- function 2: ‘document.write()’ to create a file with .html extension
- function 3: console.log() to see what the code has returned (helpful to see what the code is doing without changing the displayed site)
- function 1: prompt() to show a pop-up window (used in combo with “document.write()).
- function 2: ‘confirm()’ to show pop-up with “OK” or “Cancel” button, used with if -else statements.
Variables*[^4]
- declared with keyword
var
or let
or const
, in older browsers var
must be used;
- for general purpose use
let
, change of datatype NOT ALLOWED for const
- ex.
var x=5; var y=10; var z=x+y;
- variable names must be unique and are case-sensitive, a variable can be declared with or without values assigned
- variables can be declared in a single statement, separated with “,” and ended with “;”
- note: in operations, if a number is turned into a string, the following numbers will be treated as strings
- note: “$”, “_”, can be used like a letter as a variable name (valid as the first character as well)
Things I want to know more about
How to incorporate CSS with JavaScript?
Back to main page
References