Professional Documents
Culture Documents
Javascript Book
Javascript Book
<script> statements </script> - basic container for javascript. Usually put in the Header tag.
External JS FILES
Create a plain text but the extension is .js
Comments
// - single line comment
/* */ - multiline comment
Variable
var variableName = value – declaring a variable
3 types of variable
var – updatable variable and updatable value
let – not updatable variable but updatable value
const – cannot be update
Data Types
Numeric – basically numbers
Integers – numbers without fractional and decimal numbers
Floating-point: numbers with fractional or decimal numbers
Hexadecimal – uses digits 0 to 9 and letters A to F
String – sequence of one or more letters it is enclosed by “ “ or ‘ ‘
Null string – “ “
Escape sequences
\’ – single quotation mark
\” – double quotation mark
\b – backspace
\f – form feed
\n – new line
\r – carriage return
\t – tab
\\ - back slash
Boolean – Boolean are only true or false values
Control Structures of JavaScript
If/Else Statements
If (condition) {statements};
If (condition) {
statements
} else if (condition) {
statements
}
Else {
statements
}
Switch statements
switch (condition) {
case Case1:
case1 statements
break;
case Case2:
case2 statements
break;
default:
Default statements
}
LOOPING
WHILE LOOP
while (condition) {statements}
FOR LOOP
for (var varName = start; condition; start++) {statements}
DO WHILE LOOP
do {statements] while(condition)
OBJECTS
object.property – manipulate objects
Interval
Running code once after a specified number of seconds is only an occasionally useful procedure.
ex: var intervalId = setInterval(countdown, 1000);
clearInterval(intervalId);
USER