Hi,
👋 this is my 13th JavaScript tutorial which is
describe about void keyword in js. My previous tutorial is about math object in
js. You can go through it too.👍
So I thought to explain about less heavy concept in here.
Because last tutorials were so long. (But this is also an important concept)
Ok let’s go to the point.👇
So we are going to learn about void keyword in js.
What is void???💭
It is an important keyword which is not evaluate a return
value.
That mean when we use void as
java script function signature, then the function does not return any value. So
it takes an expression of any type as its operand and returns undefined.
OK. Let’s go to an example on js void.
<html>
<head>
<title>
java script void </title>
</head>
<body>
<form name=
my_form>
<a
href=”javascript:void (alert(‘Hi this is first void example !!!’))”>Clck
here</a>
</form>
</body>
</html>
This will show output as:
Figure 1
- The void (0) function actually returns null and it cancels the page reload too.
Try with same example that define with void (0).It will give
output as nothing.
<form name=
my_form>
<a href=”javascript:void
(0)”>Clck here</a>
</form>
OK let’s check how we can use void keyword inside js
scripts.
See below example.
Figure 2
According to this code we have three values x, y and z.
among them y and z are defined as 12 and 20. But x is not defined. So the alert
function will produce output as the same in above values.
See the image,
Figure 3
OK finally we can say simply
the void operator is used to evaluate a JavaScript expression without returning a value.
And the way is void key word is use as:
Javascript:void(function ())
the void operator is used to evaluate a JavaScript expression without returning a value.
And the way is void key word is use as:
Javascript:void(function ())
So that is void keyword and we will meet on another tutorial soon.
Bye & Thankyou!!!✋
Comments
Post a Comment