- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between JavaScript undefined and void(0)?
JavaScript undefined
It means a variable declared, but no value has been assigned a value.
For example,
var demo; alert(demo); //shows undefined alert(type of demo); //shows undefined
Here’s another example showing the usage of undefined to check whether a variable exists or not:
Example
<html> <body> <script> var age = 10; if( typeof age !== 'undefined' ) { document.write("True"); } else{ document.write("False"); } </script> </body> </html>
Output
True
JavaScript void(0)
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>
Advertisements