What is Javascript?
The vast majority of web users have at some point used a feature that was powered by javascript. Whether it’s the Facebook timeline that automatically updates on your screen or suggesting search terms as you type a few letters, those are examples of javascript in action. Javascript is the scripting language that enables these and many other web features that we take for granted. It is also the programming language that is used for back end web development.
The ECMAScript standard defines the formal specifications for the javascript programming language, and it is a cross-platform, multi-threaded scripting language. It is widely used in web development and is a core part of the Ajax programming model. It allows web developers to trap user input and manipulate HTML elements in a dynamic manner. This makes it possible to create rich Internet applications such as image sliders and games.
While it is not as portable as Java, javascript is more than capable of meeting the needs of most web development projects. All major browsers include a built-in engine that supports javascript, and the language is well-supported by tools and frameworks. Most text editors offer syntax highlighting support for the language as well.
When a javascript program is loaded by the browser, it first parses the code and turns it into a tree. This is done by breaking up each line of code into recognizable parts like keywords and functions, then saving this data in a structured way. The parsing process is also where any syntax errors are detected and fixed.
Once the AST is created, the engine can then start to execute the code. During this phase, the engine will go through each line of code and assign memory to any variables it encounters. For example, if the code contains var a = 2 then it will be assigned a value of 2. As each function is executed, the engine will also destroy its execution context.
Variables are a central part of javascript, and the language provides a number of different data types. Some of these are numeric, such as the Number type that is IEEE 754 64-bit double-precision floating point, and others are text-based, such as boolean values (true and false) and symbol values that can be used for conditional logic. The JS language also has an array-like data type known as a List.
Each variable has a unique name and a corresponding scope, which determines how the variable can be used. The scope is specified by a number of language features including the var, const and for loops. The language also has a function expression construct that can be named, which can make it easier to debug.
The javascript language has a single-threaded nature by default, but the engine that runs it will use an event loop to offload long-running tasks to other threads when necessary. For example, if the js code in the Call Stack starts an image transformation that requires a large amount of processing power, then the engine will run this code on a separate thread from the main JS code. The engine will then enqueue a callback function that will be called when the task is complete.