![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
How to unset a JavaScript variable?
To unset a variable in JavaScript, use the undefined. After that, use delete operator to completely remove it.
Let’s try the code snippet again.
var str = “Demo Text”; window.onscroll = function() { var y = this.pageYOffset; if(y > 200) { document.write(nxt); nxt = undefined; // unset delete(nxt); // this removes the variable completely document.write(nxt); // the result will be undefined } }
Advertisements