
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Happens When You Do Not Declare a Variable in JavaScript
Yes, this can be done. When you have a global scope, you can use a variable without declaring it. The following “no var” variable “points” will look at the scope chain, wince var keyword isn’t use −
<html> <body> <script> var rank = 5; points = 50; marks = 300; // Anonymous function (function() { points = 100; //overwrites global scope points var rank = 4; //new rank variable is created in this' function's scope var marks = 900; document.write(rank+"\r
"); //prints 4 document.write(points+"\r
"); //prints 100 document.write(marks+"\r
"); //prints 900 })(); document.write('<br/>'); document.write('<br/>'); document.write(rank+"\r
"); //prints 5 document.write(points+"\r
"); //prints 100 document.write(marks+"\r
"); //prints 300 </script> </body> </html>
Advertisements