Commonly Used JavaScript Functions
Overview
Variable dependencies, interval expressions, and numeric calculations are written using JavaScript.
Resources
W3 Schools JavaScript Tutorial
Microsoft's JScript User's Guide and Reference
Examples
JavaScript is case sensitive
Symbol/Function |
Description |
Example |
---|---|---|
= |
set equal to |
#myVar=5; |
== |
is equal to |
if (#myVar==3)Â #myVar2=8; |
>= |
is greater than or equal to |
if (#myVar>=1) #myVar2=9; |
> |
is greater than |
if (#myVar>4)Â #myVar2=4; |
<= |
is less than or equal to |
if (#myVar<=20) #myVar2=0; |
< |
is less than |
if (#myVar<10) #myVar2=5; |
!= |
is not equal to |
if (#myVar != 3) #myVar2=0; |
&& |
and |
if (#myVar>3 && #myVar<9) #myVar2=22; |
|| |
or |
if (#myVar==3Â || #myVar==9) #myVar2=22; |
null |
a blank value |
if (#myVar==null)Â #myVar2=null; |
isNull() |
is null |
if (isNull(#myVar)) #myVar2=9; |
!isNull() |
is not null |
if (!isNull(#myVar) #myVar2=99; |
+ |
plus |
#myVar + #myVar2; |
- |
minus |
#myVar - #myVar2; |
* |
times |
#myVar * #myVar2; |
/ |
divided by |
#myVar / #myVar2; |
// |
comment (characters following the // are comments) |
#myVar2=3;Â // set value of myVar2 equal to 3 |
/* |
block comment (/* starts the block comment and */ ends the block comment) |
/* |
Math.pow(a,b) |
a raised to the b power |
Math.pow(2,4) outputs 16 |
roundValue(#varCode, num) |
round the value of #varCode to 'num' decimal places |
roundValue(3.33333,2) outputs 3.33 |
Math.round(a) |
integer closest to a |
Math.round(5.4) outputs 5 |
Math.round(a*10^x)/10^x |
the value of a rounded to x decimal points |
[14/3 = 14.66666667] |
Math.abs(a) |
absolute value of a |
Math.abs(-5) outputs 5 |
Math.ceil(a) |
Rounds the value of a upward to its nearest integer |
Math.ceil(5.2) outputs 6 |
Math.floor(a) |
Rounds the value of a downward to its nearest integer |
Math.floor(5.8) outputs 5 |
Common Functions (**replace [ with }Â )
1) Find Current Age if given a Birth Year
function main() [Â
  var today = new Date();
  var todayYear = today.getFullYear();
  var currentAge = todayYear-V1;
  return currentAge;
]