Wednesday 25 December 2019

Javascript variable is undefined outside if condition

I have defined a javascript variable but it returns undefined.



variable = "";

if(somecondition){
variable=myString.length;

}
alert(variable);


here variable returns undefined. If I keep the alert inside the if condition, I am able to get the value but its not working if I keep the alert outside the if condition.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...