User:Lemmiwinks2/Javascript
Javascript
[edit]x+=y x=x+y
x-=y x=x-y
x*=y x=x*y
x/=y x=x/y
== is equal to
=== is equal to and same type as
!= not equal to
greeting=(visitor=="PRES")?"Dear President ":"Dear "; if vistitor=pres then greeting=dear president else greeting=dear
&& and
|| or
! not
document.write("Hello \
World!");
if (condition1)
- {
- code to be executed if condition1 is true
- }
- else if (condition2)
- {
- code to be executed if condition2 is true
- }
- else
- {
- code to be executed if condition1 and condition2 are not true
- }
switch(n)
- {
- case 1:
- execute code block 1
- break;
- case 2:
- execute code block 2
- break;
- default:
- code to be executed if n is different from case 1 and 2
- }
alert("sometext");
confirm("sometext");
prompt("sometext","defaultvalue");
function functionname(var1,var2,...,varX)
- {
- some code
- return;
- }
for (var=startvalue;var<=endvalue;var=var+increment)
- {
- code to be executed
- }
while (var<=endvalue)
- {
- code to be executed
- }
do
- {
- code to be executed
- break (optional)
- continue (optional)
- }
- while (var<=endvalue);
for (variable in array)
- {
- code to be executed
- }
onload, onUnload, onFocus, onBlur, onChange, onMouseOver, onMouseOut, onSubmit.
try
- {
- //Run some code here
- throw 'somevalue';
- }
- catch(err)
- {
- //Handle errors here
- }
string object ref var txt="Hello world!";
date object ref var myDate=new Date()
array object ref var myCars=new Array();
boolean object ref var myBoolean=new Boolean();
Math.E
Math.PI
Math.SQRT2
Math.SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
Math.round()
Math.random()
Math.floor()
var patt1=new RegExp("e");
document.write(patt1.test("The best things in life are free")); produces output 'true'.
document.write(patt1.exec("The best things in life are free")); produces output 'e'.
window object ref
browser
display screen
visited urls
current url