- 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 void in JavaScript require an argument?
The void operator is used to evaluate the given expression. After that, it returns undefined. It obtains the undefined primitive value, using void(0) i.e. 0 as an argument.
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 the JavaScript void statement evaluate an expression?
- Why does C++ require a cast for malloc() but C doesn't?
- Why do plants require nutrients?
- Why do body cells require oxygen?
- Why paddy plant require more water?
- How does “void *” differ in C and C++?
- How to use void keyword in JavaScript?
- Implement a MySQL Void Query that does nothing
- What is 'void' Operator in JavaScript?
- Argument of an Exception in Python
- What is the meaning of JavaScript void 0?
- Why final variable doesn't require initialization in main method in java?
- How to determine if an argument is sent to the JavaScript function?
- Why does the JavaScript need to start with “;”?
- If ([] == false) is true, why does ([] || true) result in []? - JavaScript

Advertisements