Void keywords in JavaScript
void is an important keyword in JavaScript that can be used as a unary operator before its single operand, which can be in any type. This operator defines an expression to be evaluated without returning a value.
Syntax
The syntax of void can be one of two types:
Example 1
The most common use of this operator is in a Client-Side javascript : URL, which allows you to estimate an expression for its secondary effects (side-effects) that the browser does not display value. of the estimated expression.
Here the alert ('Warning !!!') expression is evaluated but it is not loaded back in the current document.
Click the following, This won't react at all. href = "javascript:void(alert('Warning!!!'))" > Click me!
Result
Follow the above method to see the results
Example 2
See the following example. The following link will be nothing because the expression "0" has no effect in JavaScript. Here the expression "0" is estimated, but it is not loaded back in the current document.
Click the following, This won't react at all. href = "javascript:void(0))" > Click me!
Result
Follow the above method to see the results
Example 3
Another use of void is primarily to create undefined values as follows:
Click the following to see the result: type = "button" value = "Click Me" onclick = " getValue (); " />
Result
Follow the above method to see the results
According to Tutorialspoint
Previous article: Dialogs - Alert, Prompt, Confirmation in JavaScript
Next lesson: Print the page in JavaScript
You should read it
- ! = and! == What is the difference in JavaScript?
- Syntax of JavaScript
- Operator in JavaScript
- What is JavaScript? Can the Internet exist without JavaScript?
- JavaScript code that generates box and whisker charts containing outliers
- Boolean objects in JavaScript
- What is Currying in Javascript? How to use Currying in JavaScript
- Things to know about 'this' in JavaScript
- Udemy's top 5 JavaScript courses
- Top site with many good JavaScript exercises to practice
- What is JavaScript?
- Learn about ES6 in Javascript