JavaScript (Part 001: Introduction)

JavaScript (Part 001: Introduction)

What is JavaScript?

JavaScript is a dynamic, weakly typed programming language which is interpreted (compiled at runtime). It can be executed as part of a web page in a browser or directly on any machine ('host environment').

JavaScript was created to make web pages more dynamic. Originally, it was named LiveScript but due to the popularity of Java, it was renamed to JavaScript. JavaScript is totally independent from Java and has nothing in common with Java.

How is the JavaScript executed?

Suppose we have written our JavaScript code and we want to have some effect on the web page (if we talk about the browser as the environment where we run our script). Then we have one important thing built into any environment where we want to run JavaScript code and that's a JavaScript engine. (For example Chrome uses "V8" and Firefox uses "SpiderMonkey" as JavaScript engines.)

The job of the engine is to parse (read and understand) code, then on-the-fly compile it to machine code (machine code runs faster!). This all happens in the browser with the help of the JavaScript engine.

What do 'dynamic' and 'interpreted' mean?

JavaScript is not pre-compiled. Other languages like "C++" and "Go" are compiled during or after development. JavaScript is on-the-fly compiled and that means that the code is evaluated and executed at runtime. It also means that the code can change at runtime. (For example assigning a 'string' value to a variable which already stored a 'number'. Switching the data of a variable in other languages is not allowed!)

What does 'weakly typed' mean?

When we work with data (text data, numbers, ...) in JavaScript, we don't have to specify the type of the data. Instead data types are inferred automatically (related to the 'dynamic nature of JavaScript'). In other programming languages (strongly typed languages), we have to define the type of data a variable will hold in advanced.

JavaScript runs on a 'host environment'

A JavaScript engine can be part or can be executed in different environments. The most well-known environment is the browser (modern browsers have JavaScript engines built-in), but we can also run JavaScript in other environments (for example on the server-side).

JavaScript was invented to run in a browser to make websites more dynamic (for example working with HTML and CSS, send background HTTP requests and ...). There are also certain things JavaScript can't do when it runs in the browser environment though (for example it can't access our local file system for security reasons.)

'V8', the JavaScript engine Google developed was extracted by some people to run JavaScript anywhere. So they made it available as a standalone tool which we can execute JavaScript code anywhere else directly and this tool is called 'Node.js'. Node.js can be executed on any machine and therefore it's also used to build web back-ends (server-side JavaScript!). In Node.js we are able to access the local file system (the file system on the machine where it executes which for example is the server where it runs). But it can't manipulate HTML or CSS like browser side JavaScript is able to do.

JavaScript vs. Java

JavaScript and Java are two totally independent programming languages (different syntax, different principles, ...). They have almost nothing in common.

ECMA (European Computer Manufacturers Association)

It is an organization which will stand responsible for standardizing JavaScript. ECMA organization in the end manages a language called ECMAScript but ECMAScript and JavaScript have a strong relation. In fact, JavaScript is the most famous implementation of ECMAScript. ECMAScript isn't directly used but browser vendors implement the standard into their JavaScript engines.

Source: Udemy-JavaScript-The Complete Guide 2020

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics