Introduction to JavaScript

History of JavaScript 

According to W3.org, “JavaScript was created in 10 days in May 1995 by Brendan Eich, then working at Netscape and now of Mozilla. JavaScript was not always known as JavaScript: the original name was Mocha, a name chosen by Marc Andreessen, founder of Netscape. In September of 1995 the name was changed to LiveScript, then in December of the same year, upon receiving a trademark license from Sun, the name JavaScript was adopted. This was somewhat of a marketing move at the time, with Java being very popular around then”.

Javascript is a cross plateform object oriented scription language. Javascript is case-sensitive language. Before jQuery, Javascript is used only for client side validations in other word you can say that javascript is most underrated language. In middle of 2006 jQuery comes and it change whole concept about javascript. Now days we can do all those things which can do in server side technology. There are so many javascript library or framework available. Some of these are listed below.
1: NodeJS 2: AngularJS 3: ReactJS 4: VueJS 5: EmberJS
6: MeteorJS 7: BackboneJS 8: ExpressJS 9: WebRxJS 10: jQuery

First Program
Before going to datatypes in javascript i am just write a program which says Hello world.I am using Visual Studio. If you dont have VS then you can find from https://www.visualstudio.com/downloads/. Yon can use any editor which you want to use even you can use notepad aswell.

ConfigureProject1

Select Empty Project.

ConfigureProject2

Add New Item –> Html Page and name it Index.html

ConfigureProject3

In index.html

My First Program in Javascript

alert(“Hello world”);

Output
output

DataType
Now we write a program for hello world. Lets talk about data types. Javascript is dynamic language like any other language you dont need to declare the type of variable. If i am talking about C, C++, C#, Java and etc. you have to define the data type when you declare the variable.

In C#

int firstNumber = 10; 
string name = "Pramod";
bool onlyforstudent = true;

In Javascript

var firstNumber  = 20;
var name = "Pramod";
var onlyforstudent = true;

There are two data type in javascript.

1: Primitive datatype
2: Object datatype

datatype1

Primitive Datatype: All type which is not object data type which holds immutable value is called primitive datatype like boolean,number.
There are six primitive datatypes.
1:) Boolean : Boolean can have only two values true or false.
var onlyforstudent = true;
2:) Null: The null has only one value that is null.
var student= null;
3:) Undefined: A variable which is declared but not assigned any value
var studentDetail;
4:) Number: There is only one number type for all double, number.
var rollNo=12;
5:) String : String is use for represent textual data.
var name = “Pramod”;
6:) Symbol: Symbol is a funtion which returns a value type symbol.
var mySchool = Symbol();

Html Page

<!DOCTYPE html>
<html>
<head>
    <title>My First Program in Javascript</title>
    <meta charset="utf-8" />
</head>
<body>
    <script>
        alert("Hello world");
        var onlyforstudent = true;
        console.log(onlyforstudent);
        var student = null;
        console.log(student);
        var studentDetail;
        console.log(studentDetail);
        var rollNo = 12;
        console.log(rollNo);
        var name = "Pramod";
        console.log(name);
        var mySchool = Symbol();
        typeof mySchool;
        console.log(mySchool);
        var mySchoolObj = Object(mySchool);
        typeof mySchoolObj;
        console.log(mySchoolObj);
    </script>
</body>
</html>

Output
primitiveDatatype

2:) Object : Any data type which in not primitive is Object. Object is collection of properties. Javascript follow object literal syntax which means a list of zero or more pair of property name and associated values of an object enclosed with {}.
In javascript object is mapping between key and values. Functions are objects in javascript. Some of following objects in javascript.
1: Date
2: Array
3: Typed Arrays
4: Maps
5: Sets
6: WeakMaps
7: WeakSets

We will talk more about detail in when we learn Array in javascript.

Hope this article is helpful.

Tags: , , ,