Skip to content

Instantly share code, notes, and snippets.

@mogrady-professional
Created February 28, 2022 20:32
Show Gist options
  • Save mogrady-professional/06f75defc6ac8c149392b42c98464f3a to your computer and use it in GitHub Desktop.
Save mogrady-professional/06f75defc6ac8c149392b42c98464f3a to your computer and use it in GitHub Desktop.

Revisions

  1. mogrady-professional created this gist Feb 28, 2022.
    15 changes: 15 additions & 0 deletions console.assert.example1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    const errorMsg = 'the # is not even';
    for (let number = 2; number <= 5; number += 1) {
    console.log('the # is ' + number);
    console.assert(number % 2 === 0, {number: number, errorMsg: errorMsg});
    // or, using ES2015 object property shorthand:
    // console.assert(number % 2 === 0, {number, errorMsg});
    }
    // output:
    // the # is 2
    // the # is 3
    // Assertion failed: {number: 3, errorMsg: "the # is not even"}
    // the # is 4
    // the # is 5
    // Assertion failed: {number: 5, errorMsg: "the # is not even"}