What is javascript? Why to use javascript?—- Buzzwords explained with simplicity

What is javascript?—- Buzzwords explained with simplicity

Javascript is the one of most misunderstood language as per Douglas crockford(a famous name in the Javascript world). There will be times when you will love this language the most as well hate it as much as you can. Now lets come to the point, as per Mozilla Developer Network, JavaScript (often shortened to JS) is a lightweight, interpreted, object-oriented language with first-class functions, and is best known as the scripting language for Web pages, but it’s used in many non-browser environments as well.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/About_JavaScript

You must have noticed that it has a lot of buzzwords which kind of sounds pretty confusing. So lets extract those and look into the details.

  • lightweight:- Different people has different kind of understanding for lightweight. But, general perception for a lightweight programming language is that its easy to implement, no need of pre/post preparations required to execute your program(as in JAVA or C). Small memory footprint. Just write your JS program and execute. No special preparations required.
  • interpreted:- Javascript is an interpreted language. Instructions executed directly. As such there is no compilation. Technically its not true, what i want to say is the kind of compilation is not like of JAVA or C where you have to compile your source code to intermediate code, bytecode(in case of JAVA) or binary(in case of C) and then we execute this intermediate code to achieve our results. In case of JS just write your source code and execute it on runtime directly with no intermediary compilation codes. Compilation step in JS does not convert your source code to any intermediary code.
  • object-oriented:- JS is an object-oriented language. In JS similar to JAVA or C++ you can model your codes around objects. You can break your problem into objects and then create the objects with data and functionality. Hope no surprises with this buzzword.
  • first-class functions:- JS has first-class functions. Don’t panic, its a concept of functional programming. This concept was not present in languages like JAVA or C++. Basically, first-class functions means is that functions can be used as values. Just like a string “anoop” can be assigned to a variable, likewise in JS functions can also be assigned to a variable. Since a variable has a value, so in JS you can have a function to be a value for a variable. You can pass functions as method arguments. Lot of flexibility is provided for doing these kinds of stuffs. JAVA 8 has also adopted these kinds of flexibility w.r.t. functions.
  • scripting language:- JS is a scripting language. Scripting language is a language where instructions are written for a runtime environment. Example, shell scripting where you execute bunch of commands on a runtime environment which is our O.S. So, bundling your commands in a file becomes a script. In case of JS we are executing commands bundled as a script for our runtime environment, which is mostly Web Browser in our case. There can be multiple runtime environments but we generally use Web Browser as a runtime environment for executing JS commands. So, already a piece of software is running and we gonna execute something on it in the form of commands.

Now that buzzwords related to javascript has been explained, a new question arises why to use javascript.

When you type a URL on a browser sends a request to a server for a page. Server responds with some HTML content. The HTML content is basically a string with some bunch of tags. Browser interprets those tags and convert them into objects. Each tag becomes an object. If you have <div> tag and inside it you have <p> tag, then browser creates a parent object for div tag and child object as p tag. Basically browser creates a object tree. Its called DOM tree. View is rendered by the browser based on the DOM tree. View is tied to the DOM tree. HTML is a static language, you cannot edit this DOM tree with HTML. However, you can attach JS with your HTML file and then on your browser JS can modify the DOM tree, add a node, delete a node, edit a node. Based on this modification of DOM tree by JS view also gets modified. JS is a dynamic language, is popularly used for dynamic functionality on your browser as it gets access to the DOM tree and then you can modify the DOM tree and ultimately your view gets modified.

Leave a Reply

Your email address will not be published. Required fields are marked *