Question

I am writing a js app. I am trying to debug output of URLs that are dynamically generated. If I log the following,

console.log('string: '+false); //  string: false 

console.log(false); // false

console.log("is external url: '+'http://something.com'.substr(0,7)=='http://'); //false
//expected: is external url: true

console.log('http://something.com'.substr(0,7)=='http://'); //true

I can easily write:

console.log('is external url: ');
console.log('http://something.com'.substr(0,7)=='http://');

but I am just trying to avoid having to write two lines for each condition I want to see.

Is it possible to write the label and the test in one line of console output?

TIA -Dylan

Was it helpful?

Solution

Must debuggers console.log allows you to use commas to sepreate multiple values

console.log('string: ', false); //  string: false 

Another great way to organize data is to use groups.

console.group("iteration" + i);
console.log("current time: ", new Date());
console.groupEnd("iteration" + i);

And if you are trying to do a test, most debuggers have assertions built in

 console.assert(foobar < 100, "foobar is greater than 100");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top