JavaScript Kit > JavaScript Reference > Here
JavaScript Statements
JavaScript Statements enable you to implement logic, looping, and more within your script.
Related Tutorials
- Understanding basic arrays and loops
- Variable and expression shortcuts
- The switch statement of JavaScript1.2
- JavaScript and OOP
- Creating custom objects in JavaScript
JavaScript Statements
Statements | Description |
---|---|
const JavaScript 1.5 feature, NOT supported in IE as of IE10 |
Defines a read-only constant whose
value cannot be changed (unlike a variable using "var ").
It also cannot be re-declared once initially defined:const mysalary = 3000 //start with a letter or underscore, then alphabetic, numeric, or underscore characters
( function(){ // execute function |
var | The var statement is used
to explicitly declare a variable in JavaScript. While technically
you do not have to use the var statement in front of a
variable to create it, it is good programming practice.
Once a variable is declared, you can continue referencing that
variable without the var statement in front of it. For
example:var x=5 You can declare multiple variables at once by separating each declaration with a comma: var x, y=10, z=25, dog="Spotty" Variable names in JavaScript are case sensitive, so " -Local versus Global Scope When you use the When you use the -Copying variables- by value or by reference? In JavaScript, when you copy one variable to another, you are either:
The general rule in JavaScript is that primitive variable types (Numbers, Booleans and Strings) are manipulated by value, where as reference type variables (Arrays, objects, and functions) are manipulated by reference. This means if you copy an array to a new variable, you are in fact merely creating a new pointer to the original array. Changes to the new variable will affect the original array as well. For example: var x=[1,2,3] In the above I copy array x to a new variable y, then change array y's first element to 4. Since arrays are reference types, doing so also inexplicitly changes array x's first element to 4 as well. |
with | "with" is a time saving statement that
allows you to "cache" an object, so for statements that follow, you
no longer need to reference the object again when referring to it. Syntax: with (object) Example: with (document.form1){ In the above example, the object "document.form1" is cached, so "field1" actually refers to "document.form1.field1". |
Conditional Statements
Looping Statements
- JavaScript Operators
- JavaScript Statements
- Global functions
- JavaScript Events
- Escape Sequences
- Reserved Words