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 platform object oriented scripting language. It is case-sensitive and before jQuery, JavaScript was used only for client-side validation. In other words, you can say that JS was the most underrated language. In mid 2006, jQuery came and changed the whole concept of JavaScript. Nowadays, we can do all those things in server-side technology. There are so many JavaScript libraries or frameworks available. Some of them are listed below.
- NodeJS
- AngularJS
- ReactJS
- VueJS
- EmberJS
- MeteorJS
- BackboneJS
- ExpressJS
- WebRxJS
- jQuery
First Program
Before going to datatypes in JavaScript, I am just writing a program saying "Hello world". I am using Visual Studio. If you don't have VS, you can find it here. Yon can use any editor which you want to use; you can even use Notepad as well.
Select "Empty" Project.
Add New Item --> Html Page and name it Index.html.
In index.html
- <!DOCTYPE html>
- <html>
- <head>
- <title>My First Program in Javascript</title>
- <meta charset="utf-8" />
- </head>
- <body>
- <script>
- alert("Hello world");
- </script>
- </body>
- </html>
Output
Datatypes
Now, we are done writing our program for "Hello world". Let's talk about data types. JavaScript is dynamic language like any other programming language, so you don't need to declare the type of variable. If I am talking about C, C++, C#, Java etc., you have to define the datatype 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 datatypes in JavaScript.
- Primitive datatype
- Object datatype
Primitive Datatype
All types which hold immutable value are called primitive datatype like boolean,number. There are six primitive datatypes.
- Boolean
Boolean can have only two values - true or false.
var onlyforstudent = true;
- Null
The null has only one value that is null.
var student= null;
- Undefined
A variable which is declared but not assigned any value.
var studentDetail;
- Number
There is only one number type for all double and number.
var rollNo=12;
- String
String is used for representing textual data.
var name = "Pramod";
- 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
Object Any datatype which is not primitive is Object. Object is a collection of properties. JavaScript follows object literal syntax which means a list of zero or more pairs of property names and associated values of an object enclosed with {}.
In JS, object is nothing but mapping between key and values. Functions are objects in JavaScript. The following objects are used in JavaScript.
- Date
- Array
- Typed Arrays
- Maps
- Sets
- WeakMaps
- WeakSets
I hope this article is helpful.