源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开源教程(ossoft.cn)</title> </head> <body> <h2>JavaScript const</h2> <p>const 用于声明一个或多个常量,声明时必须进行初始化,且初始化后值不可再修改。</p> <p id="demo"></p> <script> try { const PI = 3.141592653589793; PI = 3.14; } catch (err) { document.getElementById("demo").innerHTML = err; } </script> </body> </html>
运行结果