JavaScript Void 0: Exploring the Mysteries and Realities

The term “void” means “empty space” in the dictionary. In programming, when we use this term, it means returning “nothing” or an “empty value“.

What is the void keyword?

If a function is void, it means the function does not give back anything. It’s like functions in JavaScript that absolutely return undefined.

For example:

function person() {
  return undefined
}
person()

or like this example:

function person() {
}
person()

No matter what operations or instructions are included in the functions above (such as adding four numbers or finding the average of 8 numbers), they do not provide any output.

Now that we understand the purpose of the “void” keyword. But what does “javascript:void(0)” mean?

What does javascript:void(0) mean?

If we have divided this, we have javascript: and void(0).

Let’s explore at each part in more specifics.

  • javascript:
    • This is called a Pseudo URL. When a web browser get this value as the “href” value of a link, it reads the JavaScript code after the colon (:)or rather handling the value as a normal website address.

Here’s an example code:

<a href="javascript:console.log('javascriptSample');alert('javascript Programm Succesfully Sent a Message')">Example Link</a>

When you run the code above and click the Example link the output will be:

What does javascript:void(0) mean?

As you can see in the above example, the browser doesn’t handle href as a regular path. Rather, it manage some JavaScript code and begin after “javascript:” and separated by semi-colons.

  • void(0)
    • The void operator will check the expressions and gives back an “undefined” result.

Let’s take a look at the example code here:

const adition = void(3 + 3);
console.log(adition);

When we add 3 + 3 together, we get a result, but it is not defined or clear.

Let me show you another example to confirm this:

<body>
  <h1>Welcome to JavaScript Void Tutorial</h1>
  <script>
        void(document.body.style.backgroundColor = 'blue',
             document.body.style.color = 'white'
        )
  </script>
</body>

Output:

JavaScript Void 0 example

How to combine “javascript:” and “void(0)” together?

Sometimes, you may not want a link to take you to a another page or refresh the page. By using JavaScript:, you can execute the code that doesn’t change the current page.

If joined with void(0), it is essentially means doing nothing-no refreshing, no navigation, and no execution of any code.

Here’s an example:

<a href="javascript:void(0)">Click the Link Here</a>

The word “Link” is regarded as a clickable word in a web browser. It can be preferred, but it does not take you to a different page.

When we pass 0 as an argument to the void function, it does not do anything and isn’t give any result.

You can also pass JavaScript code (like the one shown above) as an argument to the void function.

This enables the link to execute some code while staying on the same page.

Here’s an example code:

<a id="link" href="javascript:void(
document.querySelector('#link').style.color = 'red'
);">Click the Link Here!</a>

Output:

How to combine "javascript:" and "void(0)" together?

When using “void“, it will notify the browser to not show anything or give any result.

Another reason to use “javascript:void(0)” for links is when we want to run some JavaScript code without actually managing to a new page.

In such cases, we use the expressions as arguments with void.

Conclusion

In this article, we learned about the void operator. It helps us avoid a webpage from going to a different page or reloading when we click on a link with the javascript: pseudo URL.

Additional Resources

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.

Adones Evangelista


Programmer & Technical Writer at PIES IT Solution

Adones Evangelista is a programmer and writer at PIES IT Solution, author of over 900 tutorials and error-fix guides at itsourcecode.com. Specializes in JavaScript, Django, Laravel, and Python error debugging covering ValueError, TypeError, AttributeError, ModuleNotFoundError, and RuntimeError, plus C/C++ and PHP capstone projects for BSIT students.

Expertise: JavaScript · Python · Django · Laravel · Error Debugging · C/C++
 · View all posts by Adones Evangelista →

Leave a Comment