window.onload=function(){ $(document).ready(function() { alert(f); }); var f = 1 }
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> window.onload=function(){ $(document).ready(function() { alert(f);// undefined }); var f = 1; } </script> </head> <body> </body> </html>