宣言もされず,代入もされていない変数を、いきなり使うとエラーが発生する。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>宣言されていない変数の使用</title> <script type="text/javascript"> try{ alert("a="+a); // エラーが発生 a=10; }catch(e){ alert("エラーが発生しました。"); } </script> </head> <body> <h1>宣言されていない変数の使用</h1> <p>宣言もされず,代入もされていない変数を、いきなり使うとエラーが発生する。</p> <form> <button>再実行</button> </form> </body> </html>