
- 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
How to define global variable in a JavaScript function?
To declare a global variable, use the var at global scope −
<script> var myGlobalVariable; function display() { // } </script>
For JavaScript function, assign the property to a window −
<script> function display() { window. myGlobalVariable = …; } </script>
- Related Articles
- How to use a global variable in a Python function?
- How to change the value of a global variable inside of a function using JavaScript?
- How to define a function in JavaScript?
- How to declare a global variable in C++
- How to declare a global variable in PHP?
- How to declare a global variable in Python?
- How to set a global variable in Postman?
- How to create a Global Variable in Postman?
- Various ways to define a variable in JavaScript
- Create global variable in jQuery outside document.ready function?
- How to define a JavaScript function using Function() Constructor?
- How to define a variable in C++?
- How do we use function literal to define a function in JavaScript?
- How to use Global Variable in Postman Request?
- How to define functions inside a function body in JavaScript?

Advertisements