- Forums
- Javascipt
- Javascript Declare Global String In Function
i will show you how you can use a global variable in your javascript code when you declare it inside a function and you can use it outside of your scripts [2236], Last Updated: Mon Jun 24, 2024
Mrsiris
Wed Oct 06, 2010
1 Comments
616 Visits
ok, if you are new to javascript you might be wondering how you can use a variable from within a function into an outside part of your whole scripts.
i also wondered about this, because usually i would declare a variable like this within the javascript code in html page:
javascript code:
<script" language="javascript">
function Showit(){
var String = 'My String';
}
alert(String);
</script>
if i ran the code above, it would not show 'My String' so what you need to do is remove the var part so the script would look like this instead:
javascript code:
<script" language="javascript">
function Showit(){
String = 'My String';
}
alert(String);
</script>
https://www.webune.com/forums/20101006cgzf.html