js中的try...catch和java中的try...catch
java中:
try {
String x = "x";
} catch (Exception e) {
// TODO: handle exception
}
try {
System.out.println(x); //x cannot be resolved 不能被访问到
} catch (Exception e) {
// TODO: handle exception
}
js中:
try{
var x = 1;
}catch(e){
;
}try{
alert(x); //可以访问到
}catch(e){
;
}
java中:
try {
String x = "x";
} catch (Exception e) {
// TODO: handle exception
}
try {
System.out.println(x); //x cannot be resolved 不能被访问到
} catch (Exception e) {
// TODO: handle exception
}
js中:
try{
var x = 1;
}catch(e){
;
}try{
alert(x); //可以访问到
}catch(e){
;
}
var x = 1;}function fn2() {
alert(x);
}
// 无法访问
fn1();fn2();你的例子应该是可以访问的
for(var index = 0; index < 10; index++) {
}
alert(index);即时写在for里面,依然没有啥意义
在js文件第一行和最后一行的代码为// 第一行代码
(function(){
//这里开始写js代码
alert(123);
// 最后一行代码
})();