Introduction
Overview
JavaScript is the programming language of the Web. While HTML defines the structure and CSS defines the styling, JavaScript makes web pages interactive.
Originally created in just 10 days in 1995, JS has evolved into a powerhouse. Today, you can use it to build frontend UIs (React, Vue), backend servers (Node.js), mobile apps (React Native), and even machine learning models.
Syntax
Almost every programmer's first step is printing 'Hello, World!' to the screen. In JS, we use console.log() for this.
// This prints a message to the browser console
console.log("Hello, World!");
// This shows a popup alert
alert("Welcome to JavaScript!");Common Pitfalls
- Confusing Java and JavaScript. They are completely different languages with different designs (Java is to JavaScript what Car is to Carpet).
- Assuming JavaScript only runs in the browser. Thanks to Node.js, JS runs on servers too!
Interview Questions
JavaScript is a synchronous, single-threaded language by default. However, it can perform asynchronous operations using Web APIs, Promises, and the Event Loop.
ECMAScript (ES) is the official standard or specification that JavaScript follows. JavaScript is the actual implementation of that standard. (e.g., ES6 is the 6th edition of the standard released in 2015).
Real-World Example
When you click a 'Like' button on Instagram and the heart turns red instantly without refreshing the page, that's JavaScript updating the DOM.
// Select the button
const likeButton = document.querySelector('.like-btn');
// Add interactivity
likeButton.addEventListener('click', () => {
likeButton.style.color = 'red';
console.log("Post liked!");
});Check Your Knowledge
Test your understanding of Introduction with these quick questions.