JavaScript (JS)

 What is JavaScript? 

JavaScript is an object oriented programming language which is mostly used by web developers for scripting the webpages. It creates a dynamic behavior and interactive user experience when it is applied to an HTML document. JavaScript is executed as plain text, it don't need any special compilation it runs automatically when the web page loads. JS has it's own specification called ECMAScript and it does not have a relation to java. JavaScript is totally independent language. 


Special features

  • Use prototype instead of using classes for inheritance.
  • Supports all the web browsers with in built execution environments.
  • JS can be executed in  severs and other devices that has the JavaScript engine.
  • JavaScript is known as a single threaded language cause JS programs execute using a single thread.
  • It is an interpreted and case-sensitive language.
  • JS is asynchronous and the asynchronous operations are managed by an event system.

Why JavaScript is used?

JavaScript is a multi-programming programming language and it can be used in multiple domains. JavaScript is used for 

  • Web Development
             Used to create animations and widgets.

  • Game Development 
             JS can create Online Games runs on the browser.

  • Server App Development
            Frameworks such as Node.JS can be used for back end development or server side scripting.

  • Mobile App Development
            JavaScript framework such as PhoneGap or React Native can be use to create applications for multiple platforms like Android and IOS


JavaScript Frameworks.

  • Node.js

  • React
  • Angular
  • Electron


JavaScript can be used in two ways in HTML

  1. External Script.
The advantage of external scripting is code reusability. In external scripting the JavaScript files have the extension .js. It is the most practical way when the same code is used in multiple web pages.


In HTML file we have to include the name of the JavaScript file inside the script tag with the src key word.


External script file


     2.Internal Script.

The JS code for internal scripting is written within the script tags of the HTML file.
    Eg:- <script> code...  </script>



Internal script.


JavaScript Variables.

JavaScript variable hold the data values. Variables can be declared by using keywords var or let. Variable name should be unique and a value to the variable can be assign using equal (=) operator.



declaring variables.


  • Variables can be declared without keywords var or let. But it is not recommended to declare a variable without a keyword because it can overwrite an existing global variable.
       
  1. Local variable.
  • A local variable in JavaScript is declared inside a block or function. It can only be accessed from inside the function or block.

Local variable.



      2. Global Variable
  • A global variable in JavaScript is declared outside a function or with window object. Global variable can be access by using any function.


Global variable.


Key points to remember when declaring a variable.

  • Reserved words cannot be used as variable name.
  • There should be no spaces between the variable name.
      • Eg:- var my age=20;
  • Variables in JavaScript are case sensitive.
      • Eg:- A and a are different variables.
  • Variables defined without var keyword become global variables.



Resources

Comments

Popular posts from this blog

IntelliJ IDEA: The Capable & Ergonomic Java IDE by JetBrains