Introduction of JavaScript and Data Types.

Introduction of JavaScript and Data Types.

JavaScript was developed by Brendan Eich in 1995, who was a Netscape programmer. At the time of its launch, JavaScript was initially called Mocha. Then it was called Live Script and later it is known as JavaScript. JavaScript is full pledged programming language and the main purpose of javascript is to add functionality (actions) to the HTML.

JavaScript Engine:

JavaScript is pre-installed with most browsers so whatever code we write in javascript, the browser's engine is responsible to convert javascript code into machine-understandable language.

Examples of Javascript engines: Chrome-V8, Firefox-Spider Monkey, MS edge - Chakra.

Features of JavaScript:

  • Light Weight.

  • Interpreted Programming language.

  • Good for the applications which are network-centric

  • Complementary to Java

  • Complementary to HTML

  • Open source

  • Cross-platform

Advantages of JavaScript:

  • Server interaction is less

  • Interactivity is high

  • Interfaces are richer

  • Feedback to the visitors is immediate

Disadvantages of JavaScript:

  • No support for multithreading

  • No support for multiprocessing

  • Reading and writing of files is not allowed

  • No support for networking applications.

JavaScript Developer's Console:

We can use this developer's console to test our javascript coding snippets. This is just for testing purposes only and is usually not recommended for the main coding.

The process to Launch JavaScript Console: Browser->Right Click->Inspect->Console Short-cut -> (ctrl+Shift+J).

DATA TYPES :

  1. Primitive Data Types : (number, boolean, string, null, undefined,)

  2. NON- Primitive Data Types : (Arrays, Object)

A. Number: (10, -10, 10.5) All these are of 'Number' type. JavaScript never cares whether it is integral or float-point or signed and unsigned.

*******General Mathematical operators are applicable for numbers like:- 10+20=30, 10-5=5, 10\3=30, 10/2=5, 10%5=0, 10**2=100.*

*****General Operator precedence is also applicable:

10+20*4= 90, 10*(2+4)=60

B. String: Any Sequence of characters within either single quotes or double quotes is treated as a string.

Ex: 'Sagar', "Sagar", '50', "50"

We can apply + operator for strings also and it acts as concatenation operator.

Rule: If atleast one argument is of string type then + operator acts as a cocatenation operator. Ex: 'sagar'+10= sagar10

Note: We can access character of the strings by using index.

Ex: "Sagar"[0]= S, "Sagar"[1]= a, "Sagar"[4]= r, "Sagar"[10]= undefined, "Sagar"[-5]= undefined.

C. boolean: The only allowed values are true and false (case sensitive).

Ex: A=true B=false then Type of A and B is boolean.

D. null: Null means empty but it is not equals to zero and data type of null is always Object.

Ex: A=null then Type of A is object.

E. undefined: It means we are declaring the variable but not assigned any value to it and data type of undefined is undefined itself.

Ex: A= ,then Type of A is undefined.

NOTE: We can check the type of variable by using typeof keyword.