Showing posts with label Node.js. Show all posts
Showing posts with label Node.js. Show all posts

Friday, September 18, 2026

What Is JavaScript?

// programming

What Is JavaScript?

JavaScript is a programming language used extensively on the web. It allows websites to respond to users, manipulate page content, communicate with servers, process data and perform tasks dynamically.

// definition

JavaScript adds logic and behaviour

JavaScript is a high-level programming language used in web browsers, servers and many other software environments.

On a web page, JavaScript can react to user actions, change HTML content, modify CSS styles, process data and communicate with APIs.

It is one of the core technologies of modern web development alongside HTML and CSS.

// example

What does JavaScript look like?

A very simple JavaScript statement might be:

console.log("Hello, world!");

This tells JavaScript to send the text Hello, world! to the developer console.

// variables

JavaScript can store information

Variables allow programs to store values for later use.

let name = "Alice"; let orders = 4; console.log(name); console.log(orders);

Here, one variable stores text and another stores a number.

// let + const

Values can be declared with let and const

let score = 10; score = 20; const siteName = "Freelance Coder";

let is commonly used when a variable may later be assigned another value.

const creates a binding that cannot later be reassigned.

// data types

JavaScript works with different kinds of data

Type Example
String "Freelance Coder"
Number 42
Boolean true
Undefined undefined
Null null
Object { name: "Alice" }
BigInt 123n
Symbol Symbol("id")
// arrays

Arrays store collections of values

const skills = [ "HTML", "CSS", "JavaScript", "PHP" ];

Individual values can be accessed by their position.

console.log(skills[0]);

This produces:

HTML

JavaScript array indexes begin at 0. The first item therefore has index 0 rather than 1.

// objects

Objects group related information

const customer = { name: "Alice", orders: 4, active: true };

The object's properties can then be accessed:

console.log(customer.name);

This produces:

Alice
// operators

JavaScript can perform calculations

let a = 10; let b = 5; let total = a + b; console.log(total);

The result is:

15
+ - * / % **
// conditions

Programs can make decisions

Conditional statements allow code to behave differently depending on whether a condition is true or false.

const loggedIn = true; if (loggedIn) { console.log("Welcome back."); } else { console.log("Please sign in."); }
// functions

Functions package reusable behaviour

function greet(name) { return "Hello, " + name; } console.log(greet("Alice"));

The function receives a value, performs some logic and returns a result.

This makes code easier to organise and reuse.

// arrow functions

JavaScript also has arrow functions

const add = (a, b) => { return a + b; }; console.log(add(3, 4));

This outputs:

7
// loops

JavaScript can repeat tasks

for (let i = 1; i <= 5; i++) { console.log(i); }

This repeats the same instruction while the loop condition remains true.

// dom

JavaScript can change a web page

In a browser, JavaScript can interact with the Document Object Model, usually called the DOM.

Suppose the HTML contains:

<h1 id="title">Old Title</h1>

JavaScript could change it:

document.getElementById("title").textContent = "New Title";

The visible heading can change without loading an entirely new HTML document.

// events

JavaScript can respond to users

Browsers generate events when users click buttons, type into forms, move the mouse and perform other actions.

const button = document.getElementById("button"); button.addEventListener("click", function () { alert("Button clicked!"); });

JavaScript waits for the click event and then runs the function.

// html + css + javascript

The three core web technologies have different roles

HTML

Defines the structure and meaning of the page.

CSS

Controls presentation, layout and visual design.

JavaScript

Adds logic, behaviour and interactivity.

Together

They form the foundation of much of modern front-end web development.

// example

HTML, CSS and JavaScript working together

HTML:

<button id="helloButton"> Say Hello </button>

CSS:

#helloButton { background: #001eff; color: white; padding: 12px 18px; }

JavaScript:

document .getElementById("helloButton") .addEventListener("click", function () { alert("Hello!"); });

HTML creates the button, CSS styles it and JavaScript gives it behaviour.

// APIs

JavaScript can communicate with APIs

JavaScript can request data from another service over the web.

fetch("https://api.example.com/products") .then(response => response.json()) .then(data => { console.log(data); });

This example requests information from an API and converts the response into JavaScript data.

// javascript + json

JavaScript works naturally with JSON

JSON was derived from JavaScript object notation and is widely used to exchange structured information.

{ "name": "Alice", "orders": 4 }

JavaScript can parse JSON text:

const customer = JSON.parse(jsonText);

It can also convert JavaScript values into JSON:

const json = JSON.stringify(customer);
// asynchronous code

JavaScript can handle asynchronous tasks

Some operations take time, such as requesting information from a server.

JavaScript provides mechanisms such as promises and async/await for working with these tasks.

async function getData() { const response = await fetch("/api/data"); const data = await response.json(); console.log(data); }
// runtime

JavaScript is not limited to browsers

JavaScript originally became popular as a browser language, but it can now run in many other environments.

Web Browsers Servers Node.js Web Apps Desktop Apps Automation Cloud Functions
// node.js

Node.js allows JavaScript to run outside the browser

Node.js is a JavaScript runtime commonly used for server-side programming, command-line tools and automation.

console.log( "JavaScript running with Node.js" );

This means the same language can be used for both browser-based and server-side development.

// javascript vs java

JavaScript is not Java

JavaScript and Java are different programming languages. Despite the similarity in their names, they have different histories, syntax, ecosystems and execution models.

// dynamic typing

JavaScript is dynamically typed

A variable can hold values of different types at different times.

let value = 10; value = "Hello"; value = true;

The variable itself is not permanently restricted to one of these types.

// modules

JavaScript code can be divided into modules

Larger applications can separate functionality into reusable files.

export function add(a, b) { return a + b; }

Another JavaScript file can import that function:

import { add } from "./math.js"; console.log(add(2, 3));
// uses

What is JavaScript used for?

Interactive Websites Web Applications APIs Data Processing Automation Servers Forms Animations AI Interfaces Browser Tools
// summary

Structure and design become interactive.

JavaScript is a programming language used to add logic, behaviour and interactivity to websites and applications. It can manipulate HTML, change CSS, process data, respond to users, communicate with APIs and run on both browsers and servers.

What Is PHP?

// server-side programming What Is PHP ? PHP is a programming language widely use...