Why would you want to prevent code lines from running by using comments?

Yes, use comments, either single line or multiple line, either. Leave details of what your code is expected to do.

This is a fire explanation thank you very much!

1 Like

Very easy to understand thanks for that explanation!

Basically, it makes the code not work, but you can still keep it, so if what you’re testing doesn’t work, you can go back without it being erased. This is a really good explanation though. Thanks!

1 Like

Thank you for your explanation. Makes perfect sense!

1 Like

Excuse me, I have a question. Why are there slashes in the middle of the code and when I delete them, nothing works? For example:

console.log(‘The doctors were puzzled by the fact that it wasn’t quite jaundice.’);
console.log(‘If it didn’t become jaundice and went away they could discharge him.’);

There are slashes there. Except they disappear.

1 Like

If you wrap the code with markdown, it preserves the format.

The slashes are escape characters that tell the parser to treat the next character as printable.

'don\'t, doesn\'t, isn\'t, aren\'t'

@ihebissaoui this is a brilliant point that you raised and it didn’t get enough attention.

We can use multi-line comments to both hide code for bug testing, or as @midlindner said, to try out a different method of code.

Thanks guys. I totally understanding why collaboration lifts up all of our knowledge. :raised_hands:

I think we use multi-line comments when we have to write multiple lines of explanation about the code, just for better readability.

Multi line comments are well suited for commenting out sections of code because they will not remove the remainder of the line of code after */ like single line comments will.

Thank you for the explanation. this helps alot

1 Like

Makes perfect sense. Thanks

1 Like

@khalifrainey61650733 I think the use of the comment commands are to leave notes or what not, write out a key for abbreviations, full name instead of just a letter for a patient in a study , other stuff like that.
I was stuck trying to figure out what this slide wanted me to do for the longest, glad I checked in on these comments. I don’t know why the exercise asks us to run a code that deletes the Catch 22 book there. Seemed counterintuitive for me seemed like a nice enough read, poor author Joseph Heller victim of digital book burning on codeacademy

so its basically for a situation where you still want to save your work/code when trying new things out; instead of copying and pasting to notes/microsoft word and saving there

It’s also very useful in debugging. By commenting out sections of code, and then un-commenting small portions at a time, you can find where the code breaks.

Thanks. That makes so much sense!

1 Like

In my personal opinion, a reason you would want to prevent code lines from running is when looking for the cause of either a bug or an error. Commenting out pieces of code can let you see how your code is interacting and what exactly is happening under the hood as your computer jumps from one set of instructions to another.


Dave R