Debugging JS: What exactly are the Browser Differences?

Hi. This seems quite simple, but I’m not understanding what this is supposed to do? Technically I solved the challenge, but nothing logged to the FCC console OR my browser console more than once. I’d just like to know if there’s a different way I’m supposed to be running this. :confused:

I’m on chrome, btw.


// Open your browser console
let outputTwo = "This will print to the browser console 2 times";
// Use console.log() to print the outputTwo variable
console.log(outputTwo);

let outputOne = "Try to get this to log only once to the browser console";
// Use console.clear() in the next line to print the outputOne only once
console.clear();

// Use console.log() to print the outputOne variable
console.log(outputOne);


Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/debugging/understanding-the-differences-between-the-freecodecamp-and-browser-console

Your console should look like this:

1 Like

Ahhhhh, the second instance was the “undefined” that follows, not an actual second sentence.

Uf, thanks!

1 Like

It’s very difficult to write efficient JavaScript code without debugging. You must diagnose into code to find an actual root cause.

In the era of IE, most of the programmer debug using alert. But now a day’s many methods and tools added into browsers. Especially with firebug and chrome dev tools, lots of methods have been introduced.

Alert

Alert method is used from beginning of JavaScript development. It displays a value of string or variable into an alert box. Not much useful currently as more advanced methods available. It’s annoying to get a dialog on the page every time when line getting executes.

Syntax: alert(‘Hi’)

Console

Currently, Most of the developer used this method to debug. Console API has multiple methods to debug JavaScript code. Most useful is console.log that log this parameter on the console of a developer tool.

Various methods of console API: assert,clear,count,debug,dir,dirxml,error,group,groupCollapsed,groupEnd,info,log,profile,profileEnd,time,timeEnd,timeStamp,trace,warn

please can you explain better …am still confused.