0

I previously researched the definition of console.log, everyone seems to be saying it's used to debug. I'm a novice programmer, I can see that the console.log prints whatever is passed to it, such as a string or number. So can you explain how the console.log is used for debugging?

4

2 に答える 2

0

特定の時点での変数の値を理解するのに役立ちます。この方法は通常、完全なデバッガー (ブレークポイントとスタック分析を含む) が役に立たない場合に使用されます。

したがって、関心のあるポイントで関心のある変数を出力することにより、求める答えを得ることができます。

于 2013-01-27T02:05:52.747 に答える
0

デバッグは、プログラムに予期しない結果をもたらす「バグ」または問題を取り除くプロセスです。たとえば、関数で

function fed(){
    a = 3;
    b = 1;

    console.log( b );

    c = b + 3
}
fed();

console.log() は、その特定の行での実行時に b の値を「覗く」ために使用されます。

デバッガーも見つかる場合があります。コードの特定の行で停止するので便利です。

function fed(){
    a = 3;
    b = 1;

    console.log( b );

    c = b + 3;
    debugger;  //<-will stop at this line
}
fed();

HTML/javascript ファイルでこれらを試してください。bには何が含まれますか?「コンソールログ」をチェックして見つけてください

このページも役に立ち、研究に光を当てることができます:) http://www.netmagazine.com/tutorials/javascript-debugging-beginners

于 2013-01-27T02:04:56.923 に答える