JavaScript by Example

Hello, World

The simplest JavaScript program - print a message to the console.

The smallest complete JavaScript program prints a message to the console, proving the runtime is wired up and your code runs.

console.log prints its argument. In Node.js it writes to stdout. In browser devtools it writes to the console panel.

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

Running this prints:

OUTPUT
Hello, World!

In production

console.log is fine for scripts and CLI tools. In services, replace it with a structured logger like pino or winston that writes JSON - plain text logs are difficult to query in Datadog or Grafana Loki, and console.log bypasses log levels and request-ID serialization entirely.

Enjoyed this? Get more software craft delivered to your inbox.