You are on page 1of 4

JavaScript Book

<script> statements </script> - basic container for javascript. Usually put in the Header tag.

document.write(“text”) – tells the browser to insert whatever is in the parenthesis


document.lastModified – returns the date and the time the file was last change

External JS FILES
Create a plain text but the extension is .js

*in HTML - <script src=”myjavascript.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

prompt() – a method to ask for a user input

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)

Use break; to break the loop statement


Use continue; to bypass other condition in loops
FUNCTION
function funcName ([arguments]) {
statements;
}

Function with return


function funcName (arguments){
statements;
return (value);
}

OBJECTS
object.property – manipulate objects

javascript intervals and timeouts


Time Outs
setTimeout(function, miliseconds, str);
clearTimeout(id);

Interval
Running code once after a specified number of seconds is only an occasionally useful procedure.
ex: var intervalId = setInterval(countdown, 1000);
clearInterval(intervalId);

Alert, confirm, prompt


Alert - When you need to display a simple text message to the user, the alert() method is your best
choice
Confirm - When you need to ask the user a yes/no question or have the user accept or reject an action,
use the confirm() method.
Prompt - When you need to get data from the user, run the prompt() method
SYSTEM NEEDS

USER

You might also like