Basics of JavaScript


JavaScript!! How ubiquitous it is. It is in almost every website. When HTML and CSS are languages that give the structure and the style to a particular web page, JavaScript gives that web page interactive elements. In detail, JavaScript is simple, easy learning, a text-based programming language used both in client and server sides which allows making web pages interactive. It is an open-source, lightweight cross-platform. JavaScript adds behavior to web pages.

It is one of the most flexible coding languages with abilities from visual effects to data presentation to servers. 


What is JavaScript used for?

  1. Add interactive behavior to web pages
  2. Create web applications and mobile apps
  3. Game development

JavaScript Engine

Google's V8 engine is the most popular example of the JavaScript engine. V8 engine consists of 2 components.
  • Memory Heap
  • Call Stack

How does JavaScript work?

JavaScript is traditionally client-side which means each and everything performed by the browser and it responds to the user inputs. This prevents an application from putting down too much load on the server.

SYNTAX

JavaScript can be implemented using statements which placed between <script>.....</script> tags.


This script tag has two important attributes.
  1. Language
  2. Type


JavaScript Coding

  • Variables 

Variable names in JavaScript are case sensitive which n and N are two different variables. Variables.in JavaScript can be defined using var, let or const keywords.


Input
Output



  • Spaces

As JavaScript ignores white spaces and newlines anyone can feel free to use white spaces, tabs, and newlines to format the program neatly. 

  • Semicolon

Normally JavaScript statements are followed by a semicolon character. But it also allows us to omit the semicolon if each and every statement in the program is located on a separate line.


But if statements are in a single line the semicolon must be used.



However, the best case in programming is using semicolons.

  • Comments

As usual in programming also in JavaScript single-line comments start with '//'. Any text between //  and end of the line will not be executed in JavaScript. 

Multi-line comments start with '/*' and end with '*/'. Any text between /* and */ will not be executed in JavaScript. 

JavaScript also can identify the HTML type comment starts with '<!--'. JavaScript identifies this as a single line comment. But JavaScript does not identify the closing HTML tag '-->'. In JavaScript, the closing tag should be like '//-->'. 

Classes And Objects

Classes - JavaScript uses the 'class' keyword to declare a class with any particular relevant name. According to the naming conventions of coding, always a class name starts with an uppercase letter.



Objects - An object in JavaScript is an entity having properties and behaviors. We can create an object of a function using a 'new' keyword.
 

Constructor - Inside a class, it is mandatory to add a 'constructor()' method. In each and every time a class object is initialized, the constructor method is called automatically with the exact name 'constructor'. A class can contain only one constructor method. 



this keyword

'this' keyword in JavaScript refers to the object it belongs to. 
There are 4 rules which apply to this to get to know which object is referred by this keyword. 
  1. Global Scope
  2. Object's Method
  3. call() or apply() method
  4. bind() method

Global Scope:-
     If this keyword including function is called from the global scope, then that 'this' will point to the window object. Learn more



Object's Method:-
     If you create an object of a function using the 'new' keyword 'this' will point to that particular object. Learn more


call() or apply() method:-
       In JavaScript  function can be call using '()' as well as call() and apply() methods. Learn more

bind() method:-
      The bind() method is usually used to set up the context of this for a callback() function. Learn more












Comments

Popular posts from this blog

What is Application Framework

What REST Services Are

Application Framework Project