Crib Sheets
Home Page
Calculator
Chemistry
Convert Units
Electronic
First Aid
Geography
Geology
Mathematics
Music
Nautical
Numbers
Physics
VB.net Program
Weather
Web Programming
Special Chars. HTML PHP JavaScript Are You Human?

Wiring
DigitalDan Websites
DigitalDan Sites
Hit Counter 29
 
©2000-2013 DigitalDan.co.uk
 
Contact Details
Email address scroller
www.DigitalDan.uk
DigitalDan's Scientific Website
JavaScript Crib Sheet
Note
This list is not complete, it only covers popular keywords
scriptmarks start/end of JavaScript code
type="test/JavaScript"
/* .... */comment
//comment
<!-- .... \\-->used to prevent non-JavaScript browsers from running script
alertpop up text box
.charAt( .. )get character at position .. in string. (Strings start at position 0)
.charCodeAt()get the ascii value for the character at the position in a string
.fromCharCode()convert the ascii code into a character
.indexOf( .. )Return position of first occurence of substring within mainstring (Strings start at position 0)
.joinmerges all array elements into one variable
var=arrayvariable.join();
.lengthreturns number of elements in an array or characters in a string
var=arrayvariable.length;
.parseIntconvert number or string into an integer value
.reverserearrange array elements into reverse order
arrayvariable=arrayvariable.reverse();
.slicereturns some elements from an array
arrayvariable=arrayvariable.slice(firstelementnumber,lastelementnumber);
.sortsort an array
arrayvariable.sort();
.splitsplit a string into elements of an array
Split everytime key character found
arrayvariable = string.split(",");
.substrput part of string into another string
a = b.substr(start,numberOfCharactersToReturn);
string positions start at 0
.substringput part of string into another string
a = b.substr(start,(end+1));
string positions start at 0
.tostringconvert number or other variable to a string
.toLowerCaseconvert to lower case
.toUpperCaseconvert to UPPER case
Arrayused with new to define an array
breakexit loop or process
casesee switch
continuerestart loop at start of next pass
Dateuse to define a variable for dates
see note on dates
defaultdefault action if no case statement exists for current condition
doloop that takes place while a condition is true (always runs at least once)
do{ ... }while(a=b);
elsewhat to do when IF condition is not true
eval()try to extract a meaningful number from a string
falseboolean value of false
forincremental loop
for(a=1;a<=20;a=a+2;){ .... }
for ... inloop through object values
for(value in array){ .... }
functiondefines a function
ifdefines what condition must apply for code to run
inused within a for in loop
Mathsee Maths section
newdefines a new array, date or object
nullsets a variables value to undefined
promptdisplay pop-up box requesting user input
returnreturn a value from a function
switchselect one of many options depending on a variable
switch (var){
case 1:a="one"; break;
case 2:a="two"; break;
default a="many";
}
trueboolean value of true
vardefines a variable
whileLoop takes place while condition is true
while(a=b){ .. }
see also Do
withdets a default "path" for calls to window objects etc.
?variation of IF
a=b?c=d:e=f; is equivilent to
if(a=b){c=d;}else{e=f;}
+Used in maths but can also concatenate strings
ab = "a" + "b";
Date Processing
.getYear()year as yyyy
.getMonth()month as 0-11 0=Jan,11=Dec
.getDate()day number within month 0-31
.getDay()day of week as 0-6 0=Sun,6=Sat
.getHours()hour of day as 0-23
.getUTCHours()convert local hour of day to UTC, return as 0-23
.getMinutes()minutes of hour as 0-59
.getSeconds()seconds of minute as 0-59
.getMilliseconds()get milliseconds within seconds as 0-999
some browsers may handle milliseconds incorrectly
.getTimezoneOffset()getthe local time zone offset from Greenwich in minutes
.setYear()set year (tries to interpret 2 or 4 digit years)
consider .setFullYear instead
.setMonth()month as 0-11 0=Jan,11=Dec
.setDate()day number within month 0-31
.setFullYear()sets teh year part of date to 4 digit year supplied
.setHours()hour of day as 0-23
.setMinutes()minutes of hour as 0-59
.setSeconds()seconds of minute as 0-59
.setTimeout()used as timer to trigger functions
window.setTimeout(1000){ ... }
would execute 1 second after line last ran
.clearTimeout()cancel a previous .setTimeout()
Mathematics
all functions must be prefixed Math.
all angle calculations are in radians
E2.718...
LN20.693...
LN102.302...
LOG2E1.442...
LOG10E0.434...
PI3.141...
SQRT1_20.707...
SQRT21.414...
abs()absolute value
acos()arc-cosine
asin()arc-sine
atan()arc-tangent
atan2()arc-tangent from x axis
ceil()round up to next integer
cos()cosine
exp()exponent of e
floor()round down to next integer
log()natural log
max()return largest of two numbers
min()return smallest of two numbers
pow()raised to the power of
random()return a random number
value will be between 0 and 1
round()round to the nearest integer
sin()sine
sqrt()return square root of
tan()tangent
Escape Sequences
\bbackspace
\fformfeed
\nnewline
\rcarriage return
\ttab
\''
\""
\\\
Maths and Assignment
+addition
-subtraction
*multiply
/divide
%modulus (remainder)
++increment
--decrement
=set equal to
==test if equal to
+=add to original variable
-=subtrct from original variable
*=multiply original variable by
/=divide original variable by
%=get modulus from original variable
!=is NOT equal to
>is greater than
<is less than
>=is greater than or equal to
<=is less than or equal to
Comparisons
&&and
||or
!not
DigitalDan.uk is part of the DigitalDan.co.uk group