Javascript Fundamentals - (Learning Javascript Series)

Javascript fundamentals

Let us learn the fundamental of javascript. This includes knowing the common programming terms related to javascript and also how to work with them.

Some of the most common terms are:

Statement: One line of programming code; statements are often separated by semicolons (;) in JavaScript.

Variable: A named location for storing values that can be changed during program execution.

Constant: A named location for storing values that cannot be changed during program execution.

Function: A named set of statements that perform some operation and can optionally return a single value.

Keyword: A word that has a predefined meaning in JavaScript, and cannot be used for any other purpose.

Operator: Typically a symbol (such as +, -, *, or / ) that takes one or more values (called operands) and returns a result.

Expression: A combination of keywords, operators, variables, and/or functions from which a result can be calculated.

String: A sequence of 0 or more letters, numbers, or other text characters; strings are typically enclosed in quotation marks, as in “Hello World!”.

Boolean: A value or expression that evaluates to either true or false.

Literal: A Boolean, number or string that is written directly in the code. For example the expression 22/7*radius*radius contains 2 number literals.

Value: A number, Boolean, string or object.

Defining variables

We can define a variable like below:


var firstName;


var firstName

var firstName="Shiva" (declaration and initialization at same place)



Please make note that use of semicolon is not mandatory. But it is good practice to use that as it is more readable.

Variables defined in such a way can contain any type of information: numbers, strings, Booleans (true and false), or objects.


var num1=20;

var num2=39;

var sum=0;

sum=num1 + num2;

alert("The sum is: " + sum);



JavaScript 2.0 has introduced the concept of data types into JavaScript programming. Before this release of the language, programmers could not predefine the types of data. Data types are defined as follows:

var num1: Integer

Now this variable could not be assigned value other than integer.

Defining constants

Constants are only supported by the browsers which support javascript version 1.5 or higher. Firefox 5 supports constants but it is not supported by till IE8. Once a value is set to the constant it can never be changed during run time.


const PI=22/7;

PI=22/7; //this code will not give any error, but value will not be changed




Statement is the basic item in any code. It tells computer to do something. Statements can be divided into five basic categories:

  • Conditional
  • Loops
  • Object manipulation
  • Comments
  • Expressions

In the coming series we will learn more about above statements.

blog comments powered by Disqus

Posts By Month