Your very first touch on basics of Java Script
In here, I am going to focus on the main approaches of JavaScript programming language.
I want you to specially remember this article is mainly based on code segments. I’m going to let you know about all the basic concepts about JavaScript by using comments on the necessary points of my code. Since, I have to share several number of codes regarding this to you I am using my GIT repository specially created for this task. (Main content of my article will be written on the necessary pages of my GIT repository.)
I will supply
you the access to my GIT repository with all the necessary examples and
clarifications. I think you will be able to easily Guide to
the correct point of my repository by following the instructions and the
points which I have included within this article.
Please inform me if you have to face any actress issue for my GIT repository. ( * for some kind of issues Tec-Touch may have to keep it as private. you can use the forum that I have supplied on my blog page by telling that with your account name or any contact information respectively./I can make yo as my GIT repository collaborator also according to the needs.) It's better to use some IDE for developing the cords of Java Script. Also you be able to clone my file by using that.
- WebStorm IDE is one recommended for projects of Java script.
- Download WebStorm Originals by registering on JetBeans - Here to download Web Strome
- Touch this link to guide the My main code (At GIT) - VIEW CODE
(Tec-Touch) Ruvindu Kaushalya
JavaScript One of the most famous object oriented supported programming language. According to one search from stack overflow website JavaScript was the most famous programming language out of all object oriented programming languages in the world. However JavaScript has a lightweight cross-platform and interpreter programming language. JavaScript is widely used for the development of web pages. But there are many uses of JavaScript at none Browser environment also. Both client side and server site development can be done by using JavaScript programming language JavaScript has it's on library of objects and core set of language elements.
client side
Big
uses to respond from the web pages with HTML pages. Like we can have some
operations when user clicks some point of your browser HTML page and so on. Use full libraries for the client-side are ReactJS, AngularJS VueJS and so many others.
service side
supply objects get running on server which allows to communicate with the database and provide continuity of information from one invocation to another application or perform file manipulations on a server. Node.js is one of the most famous and upcoming framework of JavaScript.
The three main uses of JavaScript:-
- Full integration with HTML/CSS.
- Simple things are done simply.
- Support by
all major browsers and enabled by default.[2]
So according to all
those points I think, learning JavaScript will open your way to your own
programming career with several advantages. Today I am going to focus on
the main and the initial concepts of JavaScript which may open the door
to create the base of Huge JavaScript applications.
It is said that JavaScript is a single threaded
programming language(Itself/ Developer Perspective). and also it is weakly
typed. but in some approaches at the present we can see JavaScript can also
perform on multiple threads. However, now we can see some very clear
differences when we take the time when JavaScript was introduced to the
world.
Main concepts of Java Script
01.Class and objects.
The keyword 'new' is using when creating a new object. We can take constructor as another function in JavaScript. When function is used then 'new' keyword at the beginning of the function can act as a class in object oriented concept. (Typically before ECMAScript 5)[1].We can create a object by using object literals also.(‘{}’). But the thing is these objects are considered to be singleton. in the present days JavaScript has interview the ‘class’ keyword. so we are able to use one of those methods using class and object concepts within JavaScript. Sometimes your browser may not support class keyword because all the JavaScript engines are still adapting to the new update of JavaScript.
- Before the usage of ECMAScript 5 the object creation was somewhat different than without the usage of 'calss' keyword.
- Within [Work Number = 007] I have clearly shown you how we are able to create some kind of classes without using class keywords And how we are able to create the constructor and method by using keyword function. I have to use the prototype for adding some functionality for all the objects under those specific classes. The very first method I have created is vehicle type class by using function and then I have added paint appointed by using prototype of vehicle class. then I have maintained some static variables for maintaining the vehicle count also. and then I have created a new object of vehicle class by using a new keyword. of I have created a new Class called by inheritance the functionalities of graphical class by just using the function keyword and calling the class constructor within that. After that you can see some methods especially created only for the child class vehicle and then I have created some objects tried class and have cold some methods as well.
- Within [Work Number = 008] I have used the style after ecma5 standard by using the class keyword for creating my classes. it is just simple as that you have created the classes and objects and other object oriented programming languages. I heard Done the same example as preview previously worked for previous work this class concept also.
02. Prototypes
When one JavaScript
function has an original reference to another object called prototype.(Like
classes, another object instance). We can use it respectively when making
objects, inheritance, and methods to the java Script. Object instance also
has a prototype it is basically the object instance from which object is being
created. Object ‘__proto__’ is where object get its properties inherited from.
Functions prototype is used to inherit properties to object instances.
- Examples for using classes and prototypes 01
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");
document.getElementById("demo").innerHTML =
"My father is " + myFather.age + ". My mother is " + myMother.age;
(**document.getElementById("demo").innerHTML = is used for out put purpose)
//Out put will be = My father is 50. My mother is 48
- Examples for using classes and prototypes 02
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
Person.prototype.name = function() {
return this.firstName + " " + this.lastName
};
var myFather = new Person("John", "Doe", 50, "blue");
document.getElementById("demo").innerHTML =
"My father is " + myFather.name();
(**document.getElementById("demo").innerHTML = is used for out put purpose)
03.This Key Word
- I have to use ‘this’ keyword at several places on my cord In order to reach the current object according to the environment that I need to use it. You can see it mostly at creating the classes and within the methods.
- Getters setters(Using 'this.')
- Classes(view 'this' at methods)
04.Strect notation
As it is pronounced in in the title it is the restricted mode of JavaScript mainly used this to write secure Java Scripts. Strict make bad practices in JavaScript to errors. Also can be done great service by avoiding developer on using syntax that will get invalid in the future JavaScript developments.(Ex. - create variables without using 'var' keyword will be banned by that) Stop referring to the window object as this from outside object instances.
- Strick notation, somewhat important , let you to minimize the error ness, impliment newer
- features of java Script
05.Closure
Usually close returns another function and
it is used in JavaScript to encapsulate variables into a function and
restrict access if from the outside. When the inner function is created
JavaScript creates an environment with all the local variables from the outer
function, we call those environments and the inner function together as
closure.
- Callbacks are a common concept which is used under JavaScript methods. Here I have explained the performance of those being by using the example you can refer to that I have commented out that how do the JavaScript virtual machine is going to execute the work of cord by calling the previous previous function where they are necessary.
06.Call back and promises
I have mentioned you at the beginning JavaScript showing and asynchronous behavior because all input output operations in JavaScript is implemented to be asynchronous by the nature. (As I mentioned you above, we can continue our program without any error by maintain single thread process without waiting till the end of all the operations so as to perform well as good programming language.)
But we have to face some difficulties when
we need to you have synchronize processing of using data with this asynchronous
operations. so so we can easily solve that by using callback and
promises.
Callback is a function that is being passed to to an is promise is an object that is being returned from and on compilation of the function will be executed. promise is an object, which have enough properties to deal with as async operation synchronously , that is being returned from async tasks. that is how JavaScript could be able to handle that problem of synchronous and asynchronous operations.
As I have shown you there are callbacks and nested callbacks also using in the JavaScript programming language when the nested call back pass into sequence of asynchronous task is refers to a name ‘callback hell’. The promise object with number of properties methods and mechanism of changing to handle Complex asynchronous tasks is the solution for this introduce problem.
Within my examples I have clearly show you that
how do we can use this nested callbacks to handle those contractions by using
very simple examples. But here you will be able to use that mechanism for all
the complete operations at it usually level programming codes also.
- Promises are some kind of Operations which are used at the same places as we use callback operations. The [Work Number = 003],[Work Number = 004],[Work Number = 005] I have clearly shown you how we can use promises to call the methods at where they are necessary. Here you can see that ‘then’ is a Special keyword then is accepting another function at promise, what we do after asynchronous operation. completed(same as callback.)
07.ASYNC, AWAIT , Arrow Functions
- Those are from another main approaches of JavaScript programming language, I have implemented some examples for those main approaches also.
Picture shows some amazing uses of Java Script |
References
[1] http://en.wikipedia.org/wiki/ECMAScript
[2] https://www.geeksforgeeks.org
Comments
Post a Comment