Misc Globaleval
# jQuery.globalEval() Method
[jQuery Misc Methods](#)
## Example
Execute script in the global context
var name = "Global Variable"; $(function(){function test(){var name = "Local Variable"; alert(name); // Local Variable eval("alert(name);"); // Local Variable $.globalEval("alert(name);"); // Global Variable}test(); })
[Try it Β»](#)
* * *
## Definition and Usage
The jQuery.globalEval() function is used to execute a piece of JavaScript code globally.
**Note:** This function works similarly to the standard JavaScript eval() function. The difference is that jQuery.globalEval() executes the code in the global scope.
* * *
## Syntax
_$_.globalEval( code )
| Parameter | Description |
| :--- | :--- |
| _code_ | String. The JavaScript code string to be executed. |
* * jQuery Misc Methods](#)
YouTip