What is JavaScript?

javascript

javascript is used to provide logic and functionality for almost every web application on the internet. It is the younger brother of java and was originally created to “make web pages come alive”. Scripts can be written right in the HTML of a website and are executed automatically without needing any special preparation or compilation.

The language is an interpreted programming language which means that it executes the code line by line. This is also why it’s referred to as dynamically typed; the data types of variables are decided at runtime. A typical “Hello, World!” program written in javascript can be included in a web page using the script> tag.

When the script> tag is applied, the code is sent to a JavaScript engine which is responsible for executing the application. When a code snippet passes into the engine, it’s parsed into an abstract syntax tree, converted to machine code (0’s and 1’s) and then executed. The engine is where the magic happens and it’s where best practices should be followed to ensure that your application runs as efficiently as possible.

A number of factors influence the performance of a JavaScript engine. Several techniques such as batching DOM manipulation and reducing function calls improve performance by minimizing overhead, which in turn increases the speed at which the application is run.

Another important aspect of javascript is the concept of scoping. Functions have the ability to define their own local variables which are only accessible within the scope of that function. This allows for great flexibility and efficiency when writing functions. However, this can also lead to confusion if you aren’t careful. For example, a function can be called with fewer or more parameters than it was defined for, which will result in the function returning undefined. If you want a function to return a specific value, it should be declared as such with a return statement.

When a function is invoked, it is pushed on to the call stack, which is a LIFO data structure that manages function calls. Each stack frame contains information about the function’s arguments, local variables and the return address (where execution should continue after the function finishes). When a function is called, it’s pushes onto the top of the stack, which is why we use the convention to write all functions with an uppercase name.

Another feature of JavaScript that makes it unique is the ability to pass properties with a method call. This is useful when you need to get or set a property that may be on an object which doesn’t have a corresponding method, or when you want to access a property on a class-based object. When using this, be careful that you don’t overuse it as this can cause performance issues. Functions that are used as getters and setters create their own this binding which shadows the this value of the upper scope. This can be avoided by defining the function as an arrow function or using this-binding to explicitly specify which object you want to bind to.