zoukankan      html  css  js  c++  java
  • javascript或node中的console用法总结

     1 //建立app.js页面
     2 // 一:页面代码
     3 console.log("log信息");
     4 //在页面中执行(node app.js)这个文件会在控制台中看到log信息:"log信息"
     5 //换个方式执行:node app.js 1>info.txt(1代表重定向标准输出流);
     6 //这个时候会在app.js的同级目录下看到一个info.txt文件,里面还有"log信息".
     7 
     8 //二:依次序输出所有字符串
     9 console.log("%s","first","second");
    10 //输出结果:first second
    11 
    12 //三.将对象转换为普通字符串后执行
    13 console.log("%s","guoyansi",{name:"思思博士"});
    14 //输出结果:guoyansi { name: '思思博士' }
    15 
    16 //四:
    17 //将字符串作为数值进行转换
    18 console.log("%d","25.6");
    19 //输出结果:25.6
    20 console.log("%d","guoyansi");
    21 //输出结果:guoyansi
    22 
    23 //五  输出%
    24 console.log("%%");
    25 //输出结果:%
    26 console.log("%%","gys");
    27 //输出结果:% gys
    28 
    29 //六 将console.error信息输出到文件中去
    30 //页面代码:
    31 console.error("guoyansi is error");
    32 //利用node app.js 2>err.txt启动这个页面
    33 //会在同级目录下多一个err.txt文件.文件里面还有"guoyansi is error"
    34 
    35 //七 直接在命令行启动一个并不存在的文件javascript.js,这样:
    36 // node javascript.js 2>info.txt
    37 //输出结果:会在命令行所在的目录下多出一个文件info.txt;
    38 //info.txt文件中的内容如下
    39 
    40 
    41 /*
    42  module.js:340
    43  throw err;
    44  ^
    45  Error: Cannot find module 'E:
    odegysjavascript.js'
    46  at Function.Module._resolveFilename (module.js:338:15)
    47  at Function.Module._load (module.js:280:25)
    48  at Function.Module.runMain (module.js:497:10)
    49  at startup (node.js:119:16)
    50  at node.js:906:3
    51  */
    52 
    53 //八:console.warn的用法和console.error()用法一样
    54 
    55 //九:console.time()和console.timeEnd()输出中间代码的执行时间(注意:time和timeEnd的参数必须完全一致)
    56 console.time("for循环的时间:")
    57 var a=0;
    58 for(var i=0;i<10000000000000;i++){
    59     a++;
    60 }
    61 console.timeEnd("for循环的时间:")
    62 /*
    63  * 10.console.trace()方法将当前位置处的栈信息作为标准错误信息进行输出.
    64  *  */
    65 
    66 var obj={
    67     name:"guoyansi",
    68     age:23,
    69     eat:function(){}
    70 }
    71 console.trace(obj);
    72 //输出结果:

    不知道你能不能看懂,反正我是看不懂的.

     1 //十:console.assert()对表达式结果进行评估,如果该表达式的执行结果为false,则输出一个消息字符串并抛出AssertionError异常

    2 console.assert("g"==="s","g不等于s"); 

  • 相关阅读:
    新年放大招:Github 私库免费了!
    阿里启动新项目:Nacos,比 Eureka 更强!
    运行 Spring Boot 应用的 3 种方式
    过了所有技术面,却倒在 HR 一个问题上。。
    hdu 5428 The Factor(数学)
    poj 2385 Apple Catching(dp)
    poj 2229 Sumsets(dp 或 数学)
    poj 1759 Garland (二分搜索之其他)
    poj 3662 Telephone Lines(好题!!!二分搜索+dijkstra)
    poj 3669 Meteor Shower(bfs)
  • 原文地址:https://www.cnblogs.com/guoyansi19900907/p/4003493.html
Copyright © 2011-2022 走看看