What is Javascript?

Why do we love Javascript? Oh, you don't yet? I am sure you will by the end of this course!
Javascript is a programming language ( link to what is a programming language can be attached to the keywords here ), that helps make web pages come alive. Javascript is one of the most popular programming languages in the world, that is exactly why learning and mastering Javascript is crucial in this modern tech era.
Javascript is the programming language of the web, files in javascript are called scripts. Javascript can be written in HTML directly inside the <script> tag. Javascript can be used to add interactions to the website. It can also modify the HTML and CSS in the website.
So, What is Javascript then? Javascript is a lightweight, single-threaded, interpreted, versatile, high-level programming language. It is also known as a scripting language for web pages. It supports functional, imperative, and object-oriented programming styles.
Why is Javascript popular?
Javascript is the most popular language when it comes to web development and can be used for back-end development too. Javascript is also fairly easy to learn (opinionated), and with many rich libraries and frameworks built on top of Javascript - such as, React, Angular, etc., Javascript is currently one of the top 3 most popular programming languages in the industry.
History
Javascript was founded by Brendan Eich in 1995 while working for Netscape. Netscape intended to develop a scripting language that could make the early versions of the World Wide Web more dynamic. In the year 1996, Netscape submitted JavaScript to the European Computer Manufacturers Association (ECMA International). ECMA International is an organization that aims to standardize the use of information technology systems. Refer to the ECMA standard for more.
When Javascript was initially created, it was called "LiveScript". Java at the time was very popular, so the creators thought it made more sense to position the language closer to the word "Java" and hence the language was called Javascript.
The specification of Javascript is called ECMAScript, i.e. it is like a rule-book that tells how a scripting language is to be. As Javascript grew, there is no relation between the two languages today and Javascript is a completely independent language. The only similarity now between the two now is the word "Java" in both their names!
Today, Javascript can be used for Client-side development ( front-end ) as well as Server-side development ( back-end ). Javascript is both imperative and declarative.
Note:
- Imperative programming is a software development paradigm where Functions are implicitly coded in every step required to solve a problem. This includes step by step explanation of how and what is to be done, for now, understand this like, instructions for making a sandwich, so the instructions could be, "Get a bread to start with", "add tomatoes, cucumbers, etc", and so on till every step is explained.
- Declarative programming is a software paradigm where the "what" of the instruction is explained but now the "how". It's like saying, "Make me a sandwich", now the steps to do the same are to be figured out by the language internals themselves.
Javascript can run on any platform that has the Javascript engine ( <<Add links to the article here>> ). But for now, the Javascript engine is a software component that executes JavaScript code.
The initial Javascript engines were called interpreters, but currently, they use Just-in-time (JIT) compilation. We will learn more about this as we continue.
A quick overview of Javascript engines:
The most popular browsers in the market today are Google Chrome, Microsoft Edge, Mozilla Firefox, and Apple Safari.
Engines used by the popular browsers are as below:
V8 Engine - Google Chrome, Opera, Microsoft Edge.
SpiderMonkey - Firefox
SquirrelFish (aka JavascriptCore) - Safari.
How do Javascript engines work?
JavaScript engines, such as Google's V8, interpret and compile JavaScript code into machine code. They use a Just-In-Time (JIT) compilation process to optimize performance, converting frequently executed code into highly efficient machine code. Engines also manage memory through garbage collection, reclaiming memory occupied by objects no longer in use. This combination ensures fast execution and efficient memory management.
(Note: For an in-depth understanding of how Javascript engines work, please refer to our Javascript video lecture.)
What can Javascript do in the browser?
JavaScript can make websites interactive. By default, with HTML and CSS we can make good-looking websites but not very interactive until we use Javascript.
Imagine visiting a webpage where things change, or respond to your actions – that’s often JavaScript at work! Here are some cool things JavaScript can do in your browser:
- Animations: It can make objects move around the screen. For example, a ball can bounce, or a character can walk across the page.
- Interactive Forms: When you fill out a form online, JavaScript can check if you’ve entered the correct information before you hit submit. It can make sure your email address looks right or your password is strong enough. I am sure you have experienced this in features such as setting up a new password, right? When the passwords do not match the color turns red and the submit button gets disabled, right? That is all Javascript magic.
- Games: Many simple web games use JavaScript. You can play a game directly in your browser without needing to download anything. Most of the browser-based online games are powered by Javascript
- Dynamic Content: JavaScript can change the content on a webpage without needing to reload the page. For example, it can show new comments on a post instantly after you submit them. Or can add products to your cart in Amazon, etc.
- Responsive Menus: When you click on a menu button and it smoothly drops down to show more options, that's JavaScript making the menu responsive and user-friendly.
- Pop-up Messages: It can show pop-up messages or alerts. For instance, if you try to leave a website with unsaved changes, JavaScript can remind you to save your work.
- Image Sliders: Those cool photo galleries where pictures slide from one to another are often powered by JavaScript.
Let's look at some of the cool things that can be done with JS.
Like bringing back the extinct dinosaur on the screen? Just kidding, like this dinosaur game on chrome!

Or the cookie pop-up in websites:

Or why not make some fish swim across the screen?

JavaScript makes websites more than just text and pictures. It brings them to life, making them interactive and fun to use! There is a lot more that Javascript can do under the hood, but let's learn that in due time.
Languages built over Javascript
- TypeScript: A superset of JavaScript that adds static types to the language, (i.e. variable that is a number, will have the type "number" to ensure it does not become a string at run-time - for now, understand that certain boxes are meant for certain things and don't change - more on this later), improving code quality and developer experience. Typescript is the most popular "superset" of Javascript, taking forms as "tsx" in ReactJS. Typescript is "the most" important thing to learn after Javascript to be industry-relevant.
- CoffeeScript: A language that compiles to JavaScript, aiming to make the code more readable and succinct. This means the output code of CoffeeScript is still Javascript. Imagine we add two numbers, 2 and 3, the output is 5, similarly, if we add 4 and 1, the output is still 5, the final goal and the final output code is JS.
- Dart: Originally designed as a standalone language, it can also compile to JavaScript for running in web browsers.
- ClojureScript: A variant of the Clojure language that compiles to JavaScript, combining functional programming with JavaScript interoperability.
- PureScript: A strongly-typed, functional programming language that compiles to JavaScript, offering robust type-checking and functional paradigms.
- Flow: A static type checker for JavaScript, ensuring that your code is correct and bug-free by adding optional types.
- Brython: A Python 3 implementation that runs in the browser, allowing you to write Python code that compiles to JavaScript.
- Kotlin: A statically-typed programming language that can compile to JavaScript, enabling the use of Kotlin for both front-end and back-end development
Why is Javascript known as a light-weight Programming language?
The last I weighed its importance, it was a ton heavy. Javascript is considered a lightweight programming language due to its low CPU consumption, easy to implement, and easy-to-use syntax.
Why is Javascript Unique?
Javascript is one such programming language that can make web pages come alive, a couple of reasons that make Javascript unique are its widespread browser acceptance, i.e. to say that Javascript runs on almost all browsers today, its glued integration with HTML and CSS and ease of use.
Limitations (optional read)
- Single-Threaded: JavaScript is single-threaded, meaning it can only execute one task at a time. Although it handles asynchronous operations well, using callbacks, promises, and async/await ( all of which are discussed in future sections), CPU-intensive tasks can block the main thread, leading to performance issues.
- Security Risks: JavaScript code is executed on the client side, which makes it vulnerable to various security issues like Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF). Imagine these to be leaks in the security, say a house has 3 doors, but there is a window accidentally left open which lets the thieves steal right? Similarly, this is a way external users can hard and collect user data. These vulnerabilities can expose sensitive data and compromise user security. There are certain practices to mitigate them.
- Performance: JavaScript is interpreted rather than compiled, which can make it slower than compiled languages like C++ or Java. Although, since Javascript runs on the browser and handles the UI, it does not become much of a bottleneck. Every language has it's own ups and downs, there is no one-unique programming language.
- Lack of Type Safety: JavaScript is dynamically typed, which means type-related errors can occur at runtime, making debugging and maintenance more challenging. Although we have Typescript to the rescue.
(Note: If you have doubts about the above terms / these words might be new to you, feel free to skip this section if you are new, we will understand this better as we delve into the code)
Phew! With all the knowledge, are you ready to move to the next topic? I heard a "Hell yeah!", awesome, I will catch you in the next one.