

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Can I use a JavaScript variable before it is declared?
Yes, you can use a JavaScript variable before it is declared, with a technique called hoisting. The parser read through the complete function before running it.
The behavior in which a variable appears to be used before it's declared is known as hoisting −
For example, the following,
rank = 5; var rank;
The above works the same like the following −
var rank; rank = 2;
- Related Questions & Answers
- How can I check if a JavaScript variable is function type?
- How can I check whether a variable is defined in JavaScript?
- Can I verify if a JavaScript variable is loaded if so, how?
- Preview an image before it is uploaded in JavaScript
- Is it possible to de-structure to already-declared variables? In JavaScript?
- Can a Java array be declared as a static field, local variable or a method parameter?
- How to preview an image before it is uploaded in JavaScript?
- Is it possible to use variable for collection name using PyMongo?
- How can I use goto statement in JavaScript?
- How can I use a label with break statement in JavaScript?
- How can I use a label with continue statement in JavaScript?
- JavaScript function definition in Chrome? How can I find it?
- What is a smart pointer and when should I use it in C++?
- How can I check if a JavaScript function is defined?
- What is creative writing and how can I excel in it?
Advertisements