Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to log to the console if an error occurs using assert in Node.js

1 Answer

0 votes
const errorMsg = " is not even";
for (let num = 2; num <= 6; num++) {
    console.log(`num = ${num}`);
    console.assert(num % 2 === 0, { num }, num + errorMsg);
}



/*
run:

num = 2
num = 3
num = 4
num = 5
num = 6

Assertion failed: [object Object] 3 is not even
Assertion failed: [object Object] 5 is not even

*/

 



answered Nov 24, 2022 by avibootz

Related questions

...