JS Basics

JavaScript Introduction

Discover why JavaScript is the most popular language on the web and what you can build with it.

What is JavaScript?

JavaScript is the world's most popular programming language. JavaScript is the programming language of the Web. JavaScript is easy to learn.

  • JavaScript can change HTML content
  • JavaScript can change HTML attribute values
  • JavaScript can change HTML styles (CSS)
  • JavaScript can hide HTML elements
  • JavaScript can show HTML elements

JavaScript: The Language of the Web

JavaScript runs on the client side of the web, which can be used to design / program how the web pages behave on the occurrence of an event. JavaScript is an easy to learn and also powerful scripting language, widely used for controlling web page behavior.

Modern JavaScript

JavaScript has evolved significantly. Modern JavaScript (ES6+) includes:

  • Arrow functions
  • Template literals
  • Destructuring
  • Spread/rest operators
  • Modules
  • async/await
  • Classes

Example

javascript
// JavaScript runs in the browser!
console.log("Hello, JavaScript!");

// Change HTML content
document.getElementById("demo").innerHTML = "Hello World!";

// Variables with let and const
const name = "DevForge";
let count = 0;

// Arrow functions
const greet = (name) => `Hello, ${name}!`;
console.log(greet("World"));  // Hello, World!

// Array methods
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
const evens = numbers.filter(n => n % 2 === 0);
const sum = numbers.reduce((acc, n) => acc + n, 0);

console.log(doubled);  // [2, 4, 6, 8, 10]
console.log(evens);    // [2, 4]
console.log(sum);      // 15
Try it yourself — JAVASCRIPT