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.
- 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.
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.