JavaScript void

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

void expression evaluates the expression and returns undefined. The classic idiom void 0 is a reliable undefined value.

JavaScript Syntax

JavaScript
console.log(void 0);
console.log(void (1 + 2));
Try it Editor

How It Works

  1. Always undefined. The numeric result is discarded.
  2. void 0. Common undefined literal.

Examples

Example 1 — void IIFE

Run a function and ignore its return.

JavaScript
void function () { console.log("run"); }();
Try it Editor

How It Works

  1. Function runs for side effects.

Example 2 — vs undefined identifier

void 0 cannot be overwritten.

JavaScript
console.log(void 0 === undefined);
Try it Editor

How It Works

  1. Both are undefined values.

Frequently Asked Questions

Rarely. Prefer clear returns and undefined. void 0 still appears in some libraries.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful