
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Which one is better to use for a JavaScript link, “#” or “javascript:void(0)”?
Using “javascript:void(0)” is definitely better, since its faster. Try to run both the examples in Google Chrome with the developer tools. The “javascript:void(0)” method takes less time than the only #.
Here’s the usage of “javascript: void(0)”:
If inserting an expression into a web page results in an unwanted effect, then use JavaScript void to remove it. Adding “JavaScript:void(0)”, returns the undefined primitive value.
The void operator is used to evaluate the given expression. After that, it returns undefined. It obtains the undefined primitive value, using void(0).
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>
- Related Articles
- What is the meaning of JavaScript void 0?
- How to use void keyword in JavaScript?
- Is it better to have one big JavaScript file or multiple light files?
- What is the difference between JavaScript undefined and void(0)?
- Which is better for a beginner, Python or Ruby?
- JavaScript vs. Core Java: Which is Better?
- How to fix problems related to the JavaScript Void 0 Error?
- Which one is better POW() or POWER() in MySQL?
- Which is better for thumbnails – Canva or Picmaker?
- Which is a better destination for holidays- Coorg or Mussoorie?
- Which one is better in MySQL - NULL or empty string?
- Which one is better Build, Rebuild, or Clean in C#?
- Which one is better to insert NULL or empty string in MySQL?
- Which is better for data analysis: R or Python?
- Which is better for future skills, Go or Python?

Advertisements