Friday, July 25, 2014

Variables lifetime

- You should know that after declaring the variable it wont stay in the Ram forever it'll be delete it after you close your program or webpage  and it wont be always available wherever we want in our webpage to know more about this let see this article:
-Local variables:

  • when you declare a varaible into a function then it'll be local
  • that means you wont be able it use it out of the function braces {} and its value will be radnom since that what memory do after you finish that task you want to do with your variable the memory will use it for another thing and you should know that every varibale you make it'll have its own address in the memory but its not so important to know more about these stuff but another thing to know thats after the functon finish using this varaible it'll use it for another thing.
  • let see this example:


y wont have a value of 2 it'll have a random value or it'll show you an error in some compilers
-Global variables:
  • this kind of variables can be use in all the script why ? because we declare it out of any braces so all other function will be able to see it and use it since we know that the functions delete the local variables inside it:


now y and z will be 2 as you can see we declare x out of any function

No comments:

Post a Comment