

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use void keyword in JavaScript?
The void is an important keyword in JavaScript, which can be used as a unary operator that appears before its single operand, which may be of any type. This operator specifies an expression to be evaluated without returning a value.
The syntax of the void can be either of the following two −
<head> <script> <!-- void func() javascript:void func() or: void(func()) javascript:void(func()) //--> </script> </head>
The most common use of this operator is in a client-side javascript: URL, where it allows you to evaluate an expression for its side-effects without the browser displaying the value of the evaluated expression.
Here the expression alert ('Warning!!!') is evaluated but it is not loaded back into the current document.
Example
<html> <head> <script> <!-- //--> </script> </head> <body> <p>Click the following, This won't react at all...</p> <a href="javascript:void(alert('Warning!!!'))">Click me!</a> </body> </html>
- Related Questions & Answers
- How to use the debugger keyword in JavaScript?
- How to use 'const' keyword in JavaScript?
- How to use the 'with' keyword in JavaScript?
- How to fix problems related to the JavaScript Void 0 Error?
- How to use the 'and' keyword in Ruby?
- How to use the "defined?" keyword in Ruby?
- How to use the "not" keyword in Ruby?
- How to use the "or" keyword in Ruby?
- Use of explicit keyword in C++
- Super keyword in JavaScript?
- Class Keyword in JavaScript
- What is 'void' Operator in JavaScript?
- Why does void in JavaScript require an argument?
- How to return void from Python function?
- Compare the void agreement and a void contract
Advertisements