Javascript Syntax
by Linda Quinn
Close Window
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 (!=)
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 language="javascript" type="text/javascript">
=================================================================
This content was created by Linda Quinn of LQNet.
See http://www.lqnet.com for a great
collection of articles on this and other topics.
=================================================================
Copyright © 2006-2008, LQ Systems,Inc. All rights reserved.
====================================================================
Want an expert to help with your project?
LQ Systems, Inc.
Business Solutions
====================================================================