JavaScript Syntax



techstore
 LQ Net Home











Javascript Basics

printpage    Printer Friendly Page

Declare variables [var is lower case]
var cust;
var balance;

Declare on one line.
var cust, balance;

Declare and assign values together.
var cust = "Smith, John";
var balance = 456.30;
var totdue = price * .06;



Relational Operators
  • less than<
  • less than or equal to<=
  • greater than>
  • greater than or equal to>=
  • equal==
  • not equal (!=)

Logical Operators

  • AND &&
  • OR ||
  • NOT !

Arithmetic Operators

  • ADD +
  • SUBTRACT-
  • MULTIPY *
  • DIVIDE /
  • MODULO %
  • INCREMENT++
  • DECREMENT--

Escape Sequences

  • Backspace \b
  • Form feed\f
  • New line\n
  • Carriage return \r
  • Single quote \'
  • Double quote \"
  • Single backlash \\

Assignment Operators

 Operator   Example   Process   Description
   =     a=b     a=b   Assign
   +=     a+=b     a=(a+b)   Add value then assign
   -=     a-=b     a=(a-b)   Subtract value then assign
   *=     a*=b     a=(a*b)   Multiply value then assign
   /=     a/=b     a=(a/b)   Divide value then assign
   %=     a%=b     a=(a%b)   Modulus value then assign


if (expression) do this;

var totalnum = 5;
if (totalnum > 0) alert ("The number is " + totalnum; )

     OR

var totalnum = 5;
if (totalnum > 0)
{
     alert ("The number is " + totalnum; )
}

if (expression) do this ; else do this ;

var totalnum = 5;
var bool;
if (totalnum > 0)
{
      bool == true;
}
else
{
     bool == false;
}


if (expression) do this ; else if (expression) do this ;

var totalnum = 5;
var bool;
if (totalnum > 0)
{
      bool == true;
}
else if (totalnum < 0)
{
     bool == false;
}
else
{
     alert('The amount is 0')
}



Javascript in HTML

<script type="text/javascript">





















   Today's News





Office Depot, Inc

Tech Depot - An Office Depot Co.



Overstock.com, Inc.

























Copyright © 2006-2008, LQ Systems,Inc. All rights reserved.