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:

  type = "text/javascript" >  

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.

  type = "text/javascript" >  
 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.

  type = "text/javascript" >  
 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:

  type = "text/javascript" >  
 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

5 ★ | 1 Vote

May be interested

  • ! = and! == What is the difference in JavaScript?! = and! == What is the difference in JavaScript?
    javascript includes operators like in other languages. an operator performs some operations on one or more operands (data values) and produces a result. today's article will help readers learn about 2! = and! == operators in javascript.
  • Statistics most searched keywords Google 2018Statistics most searched keywords Google 2018
    the year of 2018 is coming to an end, google - the world's leading search engine recently announced a list of the most searched keywords in the past year. through these google trending 2018, users can see the outstanding trends that took place during the year.
  • Learn about ES6 in JavascriptLearn about ES6 in Javascript
    es6 refers to version 6 of the ecma script programming language. ecma script is the standard name for javascript and version 6 is the next version after version 5, released in 2011.
  • Build DTCL Void squad season 9Build DTCL Void squad season 9
    void dtcl season 9 will summon an egg, this egg can hatch into different support characters including the rift herald and especially baron nashor.
  • The function bsearch () in CThe function bsearch () in C
    void function * bsearch (const void * key, const void * base, nitems, size, int (* compar) (const void *, const void *)) looks for an array of nitems objects, its original member is point to by base, for a member that connects the object pointed to by the key. the size of each array element is determined by size.
  • Summary of JavaScript exercises with sample codeSummary of JavaScript exercises with sample code
    in order to make your javascript learning easier, tipsmake.com has compiled a number of javascript exercises with sample solutions for you to practice.
  • JavaScript location in HTML FileJavaScript location in HTML File
    there is flexibility in providing javascript code anywhere in an html document. however, the most preferred ways to include javascript in an html file.
  • How to Turn on JavaScriptHow to Turn on JavaScript
    javascript is a language used in many websites to provide additional functionality and access to the user. developers use javascript to deliver a large part of their site's functionality to you, the user. your browser must have javascript...
  • What is the difference between Java and JavaScript?What is the difference between Java and JavaScript?
    although the names of java and javascript seem to be related (javascript seems to be a script in java?), but that's the only similarity. these two languages ​​are not technically related to each other.
  • JavaScript code to generate error charts & graphsJavaScript code to generate error charts & graphs
    the example below illustrates a sample variance chart created with javascript that incorporates a column chart. you will also get the source code for reference and editing as you wish.