Javascript Basics

By: Nicholas C. Zakas Emailed: 1601 times Printed: 2051 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

ECMAScript is the standard that set the basics of Javascript syntax. Developers familiar with languages such as Java, C, and Perl will find ECMAScript syntax easy to pick up because it borrows syntax from each. Java and ECMAScript have several key syntax features in common, as well as some that are completely different.

The basic concepts of ECMAScript are the following:

  • Everything is case-sensitive. Just as with Java, variables, function names, operators, and everything else is case-sensitive, meaning that a variable named test is different from one named Test.
  • Variables are loosely typed. Unlike Java and C, variables in ECMAScript are not given a specific type. Instead, each variable is defined using the var operator and can be initialized with any value. This enables you to change the type of data a variable contains at any point in time (although you should avoid doing so whenever possible). Some examples:

var color = “red”;

var num = 25;

var visible = true;

  • End-of-line semicolons are optional. Java, C, and Perl require that every line end with a semicolon (;) to be syntactically correct; ECMAScript allows the developer to decide whether or not to end a line with a semicolon. If the semicolon is not provided, ECMAScript considers the end of the line as the end of the statement (similar to Visual Basic and VBScript), provided that this doesn’t break the semantics of the code. Proper coding practice is to always include the semicolons because some browsers won’t run properly without them, but according to the letter of the ECMAScript standard, both of the following lines are proper syntax:

var test1 = “red”

var test2 = “blue”;

  • Comments are the same as in Java, C, and Perl. ECMAScript borrowed its comments from these languages. There are two types of comments: single-line and multiline. The single-line comments begin with two forward-slashes (//), whereas multiline comments begin with a forward-slash and asterisk (/*) and end with an asterisk followed by a forward-slash (*/).

//this is a single-line comment

/* this is a multiline

comment */

  • Braces indicate code blocks. Another concept borrowed from Java is the code block. Code blocks are used to indicate a series of statements that should be executed in sequence and are indicated by enclosing the statements between an opening brace ({) and a closing brace (}).

For example:

if (test1 == “red”) {

test1 = “blue”;

alert(test1);

}

If you are interested in the specifics of ECMAScript’s grammar, The ECMAScript Language Specification (ECMA-262) is available for download from ECMA’s Web site, at www.ecma-international.org.


Javascript Home | All Javascript Tutorials | Latest Javascript Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(1)


1. View Comment

it is very good service.

View Tutorial          By: rajesh at 2009-11-14 02:48:18

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Nicholas C. Zakas
call() and apply() methods in Javascript
this keyword sample in Javascript
Math object and Math functions in Javascript
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Using toString() in JavaScript to convert data types to String
Javascript Basics
History and evolution of Javascript

More Tutorials in Javascript
Use WinSCP to transfer log files remotely using Javascript
Verifying user input in JavaScript
Pause execution in JavaScript
Javascript to display client date and time on webpage
Getting Browser's height and width using Javascript
Highlighting text on a page using CSS
Using revealTrans to do page transitions in Javascript
Password protect a web page using Javascript
Diabling Right Click option in a browser using Javascript
Scrolling message on the status bar using Javascript
window.frames[i] in Javascript
Form validation using Javascript
Using && in Javascript
The if statement in Javascript
do-while, while, for and for-in loops in Javascript

More Latest News
Most Viewed Articles (in Javascript )
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Typecasting in Javascript
Bitwise NOT, AND, OR, XOR operators in Javascript
History and evolution of Javascript
Math object and Math functions in Javascript
window.frames[i] in Javascript
Highlighting text on a page using CSS
Show how many characters remaining in a html text box using javascript
Javascript Basics
List of Keywords and reverved words in Javascript
Password protect a web page using Javascript
Getting Browser's height and width using Javascript
Click to remove an element from a select html form using javascript
Using toString() in JavaScript to convert data types to String
Using ! and !! in Javascript
Most Emailed Articles (in Javascript)
Using ! and !! in Javascript
Javascript Basics
Using && in Javascript
do-while, while, for and for-in loops in Javascript
switch in Javascript
this keyword sample in Javascript
Verifying user input in JavaScript
Click to remove an element from a select html form using javascript
History and evolution of Javascript
List of Keywords and reverved words in Javascript
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
The if statement in Javascript
window.frames[i] in Javascript
Password protect a web page using Javascript
Scrolling message on the status bar using Javascript