Hey everyone, in my very first post I was briefly going through JavaScript Introduction. In this post I thought of going bit more with JavaScript.

So, what is JavaScript???
Yeah as we all know that JavaScript is a scripting language also interpreted, high-level and single threaded programming language. JavaScript supports object-oriented programming and it has mostly known as client-side scripting language. Now a day JavaScript uses as server-side scripting language as well. Most important hint is that JavaScript has non-blocking I/O nature means that for the server-side development JavaScript is not waiting for I/O operation it cannot be interrupt it can handle multiple requests at a same time.
JavaScript History
Initially JavaScript named as ‘LiveScript’ but later it changed into ‘JavaScript’. Brendan Eich was named as founder of JavaScript and idea about JavaScript came in year 1995 during the time at Netscape and it was stimulated by Java.

Basic JavaScript Concepts……
In this session I’ll be talking about most vital basic concept that are available in JavaScript
- JavaScript variable
- JavaScript function
- JavaScript function as variable
- JSON
- Class, object, prototype
- ‘This’ keyword
- Closure
JavaScript Variable
Unlike other programming languages JavaScript does not have variable types. Below example code explain how to create JavaScript variables and assigning values into that variables. ”var” keyword is used to declare a variable in JavaScript.

JavaScript Function
The way how to create a function in JavaScript is showed below. JavaScript function is used to execute particular task in program. ‘”function” keyword used to create/define a JavaScript function.

JavaScript function as a variable
In JavaScript there are no limitation to assign a value into a variable. Therefore we can assign a function to a variable as well. And there is an ability in JavaScript function where we can pass a variable to a function as JavaScript function variable. JavaScript function behavior is below.

Here line 18 – 25 section, line number 25 I have passed my variable2 into variable1 function variable which is going to console out the value which i have given to variable2. And line 28-37 section, i have passed my variable2 function body into variable1 and executed that.
JSON
JSON is standard for JavaScript Object Notation. Below example exposes how to assign properties into JSON object and how to console out those assigned values.

Class, Object, Prototype
JavaScript is using a different way to create classes. By using function we can create a JavaScript class. Function which is used to create JavaScript class known as constructor function then by using this keyword we can assign properties into that class. For object creation of that particular class we used new keyword. Below example give about brief idea about class and object creation in JavaScript.

While we are talking about class and object another important keyword is prototype . As we know JavaScript has object inheritance, but not class inheritance. Each and every object reference to another object which call prototype. Actually prototype is a property of a in JS object. By using prototype keyword we can add properties in to object constructor method after creation of a class. So now go through below example to catch up a prototype idea which use to add properties.

In above example within class there is no property called age, but using prototype we have added that property into class. There is another usage of prototype which can used for implementation of inheritance as well. Below example about implement inheritance using prototype property.

“This” keyword
Same as other programming language we use this keyword to object context. Refer following examples.

above this is refers to window object and it console out that window object.


Let you all try to get the behavior of this keyword and let you all try out with hand on experience.
Closure
Closure is a function which is used inside another function. Means it is a inner function that has accessed to an outer function variable. Now go through below example.

Here in line 15 i have gone execute the function which is called calTax there i have passed 50 as parameter, now that passed value assign to vehiclepercentage. Then I have implemented function which is return a function value. Line 16 passed value assigned as returned function parameter (Inner function parameter) then the value of taxAmount will be calculate and that value consoles out.
So hope you all have come up some knowledge about JavaScript basic concept. I highly recommend you to have some hands on experience. Again I will be meeting you all with most interesting topic from my next blog post……