Web Programming - Week 2 Flashcards
Advantages of JavaScript
Speed
Rich Interfaces
Increased Interactivity
How to embed JavaScript
The HTML < script > tag in < head > or < body >
Generating Output
innerHTML
window. alert()
document. write()
console. log()
window. print()
Inputting a value
var name = window.prompt()
Declaring variables
var
let
const
Comment syntax
// - Single line /* *\ - Multi line
Return datatype of value
typeof variable
Types of variable scopes
Global - Anywhere
Function - Only within function
Block - Only inside block with let keyword
Arithmetic Operators
% Modulus
++ Increment
– Decrement
+= Adds to original value
Relational Operators
=== equal value and equal type !== not equal value or equal type
Logical Operators
&& and
|| or
! not
Conditional Statements
if (condition) {} else if (condition) {} else {}
JavaScript Switch
switch (expression) {
case value1:
default:
}
If value1 = expression, then case
If no case applied, then default
Conditional Ternary Operator
condition ? exprIfTrue: exprIfFalse
Loops and Iteration
for ([inital]; [condition]; [expression]) {} for...in for...of while (condition) {} do...while