Prev Demo
'Var' Scope Test In Javascript
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script> function Test(t) { if (t) { var name = 'Sheo'; } return name; } alert(Test(true)); // shows Sheo;' alert(Test(false)); // shows undefined </script> </head> <body> <p>How 'var' scope works in JavaScript</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output