菜单
  
    JavaScript Console Every browser has different developer tools, some are similar and some quite different but one similarity that all
    browsers have is the JavaScript Console. This is where all errors are logged, but it is often much more powerful than
    just an error log. I discuss it from a Google Chrome viewpoint, but most browsers have very similar commands.40839
    Access to variables
    Often you will want to know a variable’s value so that you can verify it is what you would expect or even just to learn
    how the data is structured (especially for objects). To do this, simply type the name of the variable into the JavaScript
    console and the value will be output below the name, this works for all types including objects and arrays. There are a
    few ways to access the variables via the console:
    After the code has r • un – If you are only interested in the final outcome, just do as I explained
    above and type the variable name.
    • Breakpoint - I will discuss breakpoints in more detail shortly but as with debuggers in many
    other languages, you are able to add a breakpoint that allows you to examine the variables at
    the point that the code at the breakpoint is executed.
    • Debugger Statements - You can manually add breakpoints in your code by writing debugger;
    in your code. It is generally easier to use breakpoints, but worth knowing about the debugger
    statement.
    • Inside the code – You can log to the console from within the code. It is usually easier to use
    breakpoints but if you wish to you can log by writing console.log('foo'); within the code.
    • As a table – This is currently only available in Google Chrome and Firebug but it is
    a very useful way to view arrays as tabular data where each index is a row. By running
    console.table(array); from either within the code or within the console (I would
    recommend straight from console, during a breakpoint, since it is not compatible with
    other browsers).
    Prompt
    The area that you are able to type into within the console is known as the prompt, since it is used in much the same
    way as a shell (command line) prompt is used. This is very useful for accessing the console API, such as console.log
    and console.table. But it is also far more powerful, since it can evaluate expressions. These could be as basic as
    simple calculation (the answer gets outputted straight away) or something more specific to the page you’re on such
    as modifying the DOM. In fact, you can write any JavaScript within the prompt, which makes it an invaluable tool
    for debugging since you can for example take a function that is not working as you would expect it to and modify it
    without affecting the rest of the script.
    Sources
    As with the console, most JavaScript debugging tools (within browsers and/or plugins) have a way to view the source
    code - which makes sense since you usually need to see the code to understand and debug it – but it is not just read-only.
    These tools allow you to manipulate and debug the code line by line. In Google Chrome, it is found under the
    ‘Sources’ tab, although most of the features are available in most other tools too.
    Live editing
    Sometimes you want to be able to write a line or code or test out a function, that is what the prompt is for, but
    sometimes you want to change the code itself a variety of times and to see how it does affect the rest of the codebase.
    Rather than using the prompt or repeatedly saving in your text editor, you can go into the source tab and directly edit
    the code. This will run it in a new instance of the JavaScript Virtual Machine so that you can test and debug all you
    need to without overwriting the original file (which would then need to be refreshed, and you may lose useful code
    et cetera).
    Breakpoints
  1. 上一篇:ASP.NET技术英文文献和中文翻译
  2. 下一篇:MVC设计模式和Spring,Struts框架英文文献和中文翻译
  1. 汽车乘员舱的声振耦合英文文献和中文翻译

  2. 立体光照成型的注塑模具...

  3. 低频振动的铁路车轴的状...

  4. 接头的形状对沥青塞接头...

  5. 电-气动驱动的垂直计算机...

  6. 开口端纺纱系统中的锥形...

  7. 木质填料聚丙烯复合材料...

  8. java+mysql车辆管理系统的设计+源代码

  9. 河岸冲刷和泥沙淤积的监测国内外研究现状

  10. 当代大学生慈善意识研究+文献综述

  11. 杂拟谷盗体内共生菌沃尔...

  12. 大众媒体对公共政策制定的影响

  13. 十二层带中心支撑钢结构...

  14. 中考体育项目与体育教学合理结合的研究

  15. 酸性水汽提装置总汽提塔设计+CAD图纸

  16. 乳业同业并购式全产业链...

  17. 电站锅炉暖风器设计任务书

  

About

751论文网手机版...

主页:http://www.751com.cn

关闭返回