JavaScript Basics – The Fundamentals of JavaScript

Author: satz | Date: September 17, 2009

This article briefly explains the fundamentals of JavaScript.  The basic characteristics, features, usage, etc. have been explained in simple terms. Topics like,  What is JavaScript ?,  How can we use the JavaScript ? , Where to place a JavaScript code ?,  Characteristics of JavaScript,  JavaScript variables,  JavaScript operators, etc. are explained in a simple manner.

What is JavaScript?

  • It adds interactivity to HTML pages
  • It is a scripting Language
  • Light-weight script
  • It can be embedded directly to HTML page.
  • It is an interpreted language
  • It is FREE to use.
  • Real name is ECMA script

JavaScript can be used for

  • Making HTML pages dynamic and interactive.
  • Data validation
  • Detecting browser and serving specific content to the visitor.
  • Creating cookies.

Where to place a JavaScript Code

  • Inside the <head> tag
  • Inside the <body> tag
  • Inside both <head> and <body>
  • In External files.

Characteristics of JavaScript

  • It is case sensitive.
  • At the end of each executable statement, semicolon (;) is used (Optional).
  • JavaScript statements are grouped together in blocks which starts with left curly bracket ({) and ends with right curly (}) bracket.
  • Can be commented using //…and /*….*/.

JavaScript Variables

  • JavaScript variables are case sensitive and should begin either with a letter or the underscore character.
  • JavaScript variable can be declared using var statement as well as without var statement.
  • Quotes should be used around the value, while declaring a value to a JavaScript variable.
  • While re-declaring a JavaScript variable, it will not loose its original value.
  • Arithmetic operations can be done using JavaScript.

JavaScript Operators

  • There are arithmetic operators which are used to perform arithmetic between and/or values.
    eg: +,-,*,/,%,++,–,etc.
  • There are assignment operators which are used to assign values to JavaScript.
    eg: =,+=,-=,*=,%=,

NOTE: The + operator can be used to concatenate two variable values. Adding two strings OR a number and a string will result in a string. Where as adding two numbers will result in a number.

  • There are comparison operators which are used in logical statements to determine equality or difference between variables or values.
    eg: = =, !=, = = =, < , >,>=, <=, etc.
  • There are logical operators used to determine the logic between variables or values.
    eg: &&, ||, ! ,etc.
  • There are conditional operators used to assign values to a variable based on some conditions.
    eg: variablename=(condition)?value1:value2