
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is the difference between Declaring and Initializing a variable in JavaScript?
The following is stated about declaration and initialization of a variable in ECMAScript specification −
A var statement declares variables that are scoped to the running execution context’s VariableEnvironment. Var variables are created when their containing Lexical Environment is instantiated and are initialized to undefined when created. [...] A variable defined by a VariableDeclaration with an Initializer is assigned the value of its Initializer’s AssignmentExpression when the VariableDeclaration is executed, not when the variable is created.
The above defines the difference:
- All variables are initialized with the value undefined.
- Variables declarations are initialized with undefined upon the initialization of their lexical environment.
- This initialization does not work as an assignment.
- Related Articles
- Difference between declaring a variable before or in a Java loop.
- Can re-declaring a variable destroy the value of that variable in JavaScript?
- What is the difference between a variable and StringVar() of Tkinter?
- Must you define a data type when declaring a variable in JavaScript?
- What is the difference between a++ and ++a in JavaScript?
- What is the use of declaring variables in JavaScript?
- What is the difference between == and === in JavaScript?
- What is the difference between comments /*...*/ and /**...*/ in JavaScript?
- What is the difference between jQuery and JavaScript?
- What is the difference between Java and JavaScript?
- What is the difference between JavaScript and ECMAScript?
- What is the difference between JavaScript and C++?
- What is the best way of declaring multiple Variables in JavaScript?
- What is the difference between functions and methods in JavaScript?
- What is the difference between setTimeout() and setInterval() in JavaScript?

Advertisements