Introduction
Overview
JavaScript is a programming language that was created by Brendan Eich in 1995 to add interactivity to web pages. Initially, it was called LiveScript, but later it was renamed to JavaScript.
It runs in the browser and on the server. JavaScript is a dynamic, weakly typed, and interpreted programming language. It is a multi-paradigm language, which means that it supports different programming styles like object-oriented, functional, and imperative programming.
Uses of JavaScript
JavaScript is a programming language that is commonly used in software development in several contexts. Here are some examples of how JavaScript is used in different areas of software development like frontend, backend, mobile, desktop, game development, etc. Let's see how JavaScript is used in different areas of software development.
Frontend development
JavaScript is commonly used to create the front end of web applications, which is the part of the application that users interact with. Frontend developers use JavaScript to create the user interface and add interactivity to web pages. Many JavaScript frameworks are specifically designed for frontend development, which is the process of creating the user interface and adding interactivity to web pages. These frameworks provide pre-built libraries and tools that can be used to quickly and easily build front-end applications. Some popular JavaScript frameworks for frontend development include:
- React
- Angular
- Vue.js
- Next.js
- Gatsby
- Nuxt.js
- Svelte
Backend development
JavaScript is also used on the backend, or server-side, of web applications. With the rise of Node.js, JavaScript has become a popular choice for backend development, as it allows developers to use the same language on both the front end and back end of an application. Many JavaScript frameworks are specifically designed for backend development, which is the process of building and maintaining the server side of a web application. These frameworks provide pre-built libraries and tools that can be used to quickly and easily build backend applications. Some popular JavaScript frameworks for backend development include:
- Express
- Nest.js
- LoopBack
- Hapi
- Sails.js
Mobile development
JavaScript could be used to create mobile applications using tools like React Native or PhoneGap. React is leading in hybrid mobile app development, which allows developers to use the same codebase to build both iOS and Android applications.
Desktop development
JavaScript can be used to create desktop applications using tools like Electron.
Game development
JavaScript can be used to create games using frameworks like Phaser or Pixi.js.
Overall, JavaScript is a versatile language that is used in a variety of different contexts in software development. It is particularly popular for web development, but it can also be used to create a wide range of other types of applications.
History and evolution of JavaScript
As we have seen, JavaScript was created by Brendan Eich in 1995. ECMAScript (shortly ES) is the official name of the JavaScript standard. It is maintained by the European Computer Manufacturers Association (ECMA) and is the standard that all JavaScript engines must follow.
JavaScript has undergone several versions over the years. The most widely used versions are:
- ES1 - also known as ECMAScript 1, released in 1997
- ES2 - 1998
- ES3 - 1999
- ES5 - 2009
- ES6 - 2015
- ES7 - 2016
- ES8 - 2017
- ES9 - 2018
- ES10 - 2019
- ES11 - 2020
- ES12 - 2021
The features listed below use technical terms that will be explained in upcoming sections. For now, focus on understanding JavaScript's evolution. You'll dive deeper into these features as you progress through the documentation.
ES1 - 1997
Introduced the basic syntax of the language, including variables, operators, and control statements.
ES2 - 1998
Introduced the with statement, which allows you to create a new scope for a block of code. It also introduced the for-in loop, which allows you to iterate over the properties of an object.
ES3 - 1999
Introduced regular expressions, better string handling, new control statements, and try-catch exception handling. It also improved the handling of errors and introduced the strict mode, which helps to prevent some common JavaScript errors.
ES5 - 2009
Made improvements to the language such as better support for arrays, new methods for working with strings and objects, and the ability to create more efficient code using strict mode. It also introduced new methods to help prevent and fix common coding mistakes.
ES6 - 2015
ES6 is a significant update to the language, introducing many new features and improvements. Some notable features include:
letandconstfor variable declarations - to declare variables that are block-scoped- arrow functions - a shorter syntax for writing functions i.e.
const add = (a, b) => a + b - template literals - backticks (``) for string interpolation and multi-line strings
- classes and inheritance - a way to create objects and classes
- destructuring assignment - to unpack values from arrays and objects into distinct variables
- default function parameters - to set default values for function parameters
Promisesfor handling asynchronous code - a more readable way to handle asynchronous code- and many more improvements and additions to the language
ES7 - 2016
ES7 introduced several new features, including:
Array.prototype.includes()- method to check if an array contains a value or not i.e.array.includes(value)returnstrueif the array contains the value, andfalseif it does not- Exponentiation operator (
**) - to calculate the power of a number (e.g.2 ** 3is8) - and many more improvements and additions to the language
ES8 - 2017
It includes:
Object.values()andObject.entries()- methods to get the values and entries of an object as an array (e.g.Object.values({ name: 'John', age: 30 })returns['John', 30])- String padding - to add padding to a string using the
padStart()andpadEnd()methods (e.g.'hello'.padStart(10)returns' hello') Object.getOwnPropertyDescriptors()- method to get the descriptors of an objectasyncfunctions - asynchronous functions that return aPromiseand can use theawaitkeyword- and more improvements and additions to the language
ES9 - 2018
It introduced:
- Asynchronous iteration - to iterate over asynchronous data i.e.
for await (const value of asyncIterable) { ... } - rest/spread properties for objects - to copy objects and merge objects using the spread operator (
...) i.e.{ ...obj1, ...obj2 } promise.finally()- to execute code after aPromiseis settled (either fulfilled or rejected)- template literals improvements - to use raw strings and to tag template literals
- and many others
ES10 - 2019
It included:
Array.flat()andArray.flatMap()- to flatten arrays and to flatten arrays and map them at the same timeObject.fromEntries()- to convert an array of key-value pairs into an object i.e.Object.fromEntries([['foo', 1], ['bar', 2]])//{foo: 1, bar: 2}String.trimStart()andString.trimEnd()- to trim whitespace from the beginning and end of a string- and others
ES11 - 2020
It introduced:
- Dynamic
import()- to import modules dynamically (i.e. at runtime) - globalThis - to get the global object i.e.
globalThisis the same aswindowin the browser andglobalin Node.js - Nullish coalescing operator (
??) - to return the right-hand side operand when the left-hand side operand isnullorundefined - Optional chaining operator (
?.) - to access properties of nested objects without having to check if the parent object exists or not BigInt- to represent integers larger than 2^53 - 1 which is the largest number JavaScript can reliably represent with the Number primitive and represented by the Number.MAX_SAFE_INTEGER constant- and others
ES12 - 2021
It includes:
- Logical assignment operators - to assign values to variables based on a condition (e.g.
x ||= yis the same asx = x || y) - Numeric separators - to make large numbers more readable (e.g.
1_000_000instead of1000000) Promise.any()- resolves as soon as any one of the promises resolvesString.prototype.replaceAll()- replaces all occurrences of a substring in a string- and others
It's worth noting that not all browsers or JavaScript engines support the latest version of ECMAScript, so it's important to keep that in mind when developing applications that need to run on multiple platforms, because some features may not be supported on all browsers, like Internet Explorer.
JavaScript engines
JavaScript engines are programs that execute JavaScript code. They parse and compile JavaScript code, then execute it. The most popular JavaScript engines are:
- V8 - Used by Chrome, Edge, Node.js, and Opera
- SpiderMonkey - Used by Firefox
- JavaScriptCore (Nitro) - Used by Safari
- Hermes - Used by React Native
Each engine implements the ECMAScript standard but may have different performance characteristics and optimization strategies.
All the JavaScript engines mentioned above are open-source, so you can check them out on GitHub. These engines are written in C++, C, and Rust.
Conclusion
You now have a foundational understanding of JavaScript's history, its versatile applications across different development domains (frontend, backend, mobile, desktop), and the JavaScript engines that power it. As you progress through this documentation, you'll learn how to write JavaScript code and explore its core concepts in depth.