如何用浏览器调试出js代码

请问下面的程序为什么我输入到谷歌和火狐里面的console里面没有反应,没有像注释一样给我打印出值

function test(o) {
 var i = 0; // i is defined throughout function
 if (typeof o == "object") {
 var j = 0; // j is defined everywhere, not just block
 for(var k=0; k < 10; k++) { // k is defined everywhere, not just loop
 console.log(k); // print numbers 0 through 9
 }
 console.log(k); // k is still defined: prints 10
 }
 console.log(j); // j is defined, but may not be initialized
}
阅读 1.4k
1 个回答

你这只是一个方法,没有调用它

function test(o) {
 var i = 0; // i is defined throughout function
 if (typeof o == "object") {
 var j = 0; // j is defined everywhere, not just block
 for(var k=0; k < 10; k++) { // k is defined everywhere, not just loop
 console.log(k); // print numbers 0 through 9
 }
 console.log(k); // k is still defined: prints 10
 }
 console.log(j); // j is defined, but may not be initialized
}
test({a: '1'})

这样不就好了么

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题