- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why does the JavaScript void statement evaluate an expression?
The JavaScript void returns an expression to remove the side effect and return the undefined primitive value. This side effect may occur while inserting expression in a web page.
Let’s see an example of the void. The void(0) can be used with hyperlinks to obtain the undefined primitive value,
Example
<!DOCTYPE html> <html> <head> <title>Understanding JavaScript void(0)</title> </head> <body> <a href="javascript:void(0);" ondblclick="alert('Click it twice!')">Click me not once, but twice.</a> </body> </html>
We used JavaScript:void(0) above to prevent the page from reloading when the button is clicked the first time.
The code will only work when the button will be clicked twice. If it is clicked once, then nothing happens. But the alert box comes over when the button is clicked twice since we used the ondblclick event handler.
- Related Articles
- Why does void in JavaScript require an argument?
- C++ Program to Evaluate an Expression using Stacks
- Evaluate Postfix Expression
- How does MySQL evaluate the expression if the arguments are not equal in NULLIF()?
- Why does Lua have no “continue” statement?
- Evaluate an array expression with numbers, + and - in C++
- Evaluate the lowest cost contraction order for an einsum expression in Python
- Program to build and evaluate an expression tree using Python
- Write the following statement as an expression:5 added to $x$.
- How does “void *” differ in C and C++?
- Implement a MySQL Void Query that does nothing
- How does JavaScript 'return' statement work?
- Why does MySQL evaluate “TRUE or TRUE and FALSE” to true?
- What is the meaning of JavaScript void 0?
- What does the operator || do in a var statement in JavaScript?

Advertisements