Saturday, February 24, 2018

JavaScript Basics I

Hello Everyone,

I am writting this post to express the knowledge that got through learning Javascript in my AF module in the university.
Firstly I will introduce what Javascript(JS) is,
  • JS is a programming language which is used add some client side validations to static HTML pages.
  • It is an interpreted language
  • It uses nIO(non blocking IO) to avoid concurrency issues
  • Nowadys there several JS frameworks namely AngularJS, ExpressJS, NodeJS, ReactJS are some.

Simplest of JS code For a beginning


In HTML code we define <script> tag where all the JS codes are written in between those tags

Lets Learn more basic stuff about JS



In here we defines a object from function using new keyword and initialize with parameter. If we use var.marks instead of this.marks we cannot access marks outside of the function as var has local scope.


Output to the console



Next we'll talk about an another interesting feature JS process i.e. Prototyping. Prototyping is refers to as referring different object inside of  a function.
Let's simplifies this using an example.




In this code when the function is already defined we cannot add more behaviours. So in order to add more behaviors we use prototype objects.If we try add behavior using Student.id it will be an undefined case.So to avoid these prototype object can be used.Also prototype objects can be used to add new methods objects constructors.
               

Output to the console



I hope you guys learnt something from this.Hope to see you in the 2nd part of this which talks about inheritance and prototyping together.See you in that.


©Copyright Viraj Wickramasinghe.

No comments:

Post a Comment