What is “assert” in JavaScript?

后端 未结 14 691
-上瘾入骨i
-上瘾入骨i 2020-12-04 05:03

What does assert mean in JavaScript?

I’ve seen something like:

assert(function1() && function2() && function3(), \"some          


        
相关标签:
14条回答
  • 2020-12-04 05:33

    As mentioned by T.J., There is no assert in JavaScript. However, there is a node module named assert, which is used mostly for testing. so, you might see code like:

    const assert = require('assert');
    assert(5 > 7);
    
    0 讨论(0)
  • 2020-12-04 05:34

    In addition to other options like console.assert or rolling your own, you can use invariant. It has a couple of unique features:

    • It supports formatted error messages (using a %s specifier).
    • In production environments (as determined by the Node.js or Webpack environment), the error message is optional, allowing for (slightly) smaller .js.
    0 讨论(0)
提交回复
热议问题