User Name:

User Email:

This information will only be saved for the purposes of communicating with those who have provided this information voluntarily regarding our services.We will never sell your name or email address to anyone.
© 2021 - First Crazy Developer (Abhishek Kumar)

crazydeveloper JavaScript Basic Tutorial - Part 1

Java Script First Example: Simple Calculation


  var num1, num2, sum

  num1 = prompt("Enter first number")

  num2 = prompt("Enter second number")

  sum = parseInt(num1) + parseInt(num2)

  alert("Sum = " + sum)


Language Basics:

  • JavaScript is case sensitive
  • HTML is not case sensitive;   onClick, ONCLICK, … are HTML
  • Statements terminated by returns or semi-colons (;)
              x = x+1;    same as      x = x+1
  • Semi-colons can be a good idea, to reduce errors
  • “Blocks”
  • Group statements using  { … }
  • Not a separate scope, unlike other languages (see later slide)
  • Variables
Define a variable using the var statement
Define implicitly by its first use, which must be an assignment
Implicit definition has global scope, even if it occurs in nested scope?

JavaScript blocks:

  • Use { } for grouping; not a separate scope

js> var x=3;

js> x


js> {var x=4; x}


js> x


  • Not blocks in the sense of other languages
Only function calls and the with  statement cause a change of scope

JavaScript primitive datatypes:

  • Boolean 
Two values: true and false
  • Number
64-bit floating point, similar to Java double and Double
No integer type
Special values NaN  (not a number) and Infinity
  • String 
Sequence of zero or more Unicode characters
No separate character type (just strings of length 1)
Literal strings using ' or " characters  (must match)
  • Special values 
null  and undefined
typeof(null) = object;     typeof(undefined)=undefined


  • An object is a collection of named properties
Simple view: hash table or associative array
Can define by set of name:value pairs
–objBob = {name: “Bob", grade: 'A', level: 3};
New members can be added at any time
–objBob.fullname = 'Robert';
Can have methods, can refer to this 
  • Arrays, functions regarded as objects
A property of an object may be a function (=method)
A function defines an object with method called “( )”

   function max(x,y) { if (x>y) return x; else return y;};

   max.description = “return the maximum of two arguments”;



crazydeveloper Home Page 26 January 2017

Become a Fan