Console.log questions

I have 3 questions regarding the use of the console.log function:

  1. The console can process 10>9 , with no parenthesis, nor semi-colon added, but the formula 10=9 triggers an error - why is that? Why doesn’t it say “false”?

  2. Clearing the console in Google chrome sometime leaves the top row standing. Why is this? Shouldn’t the console clear completely when hitting the the circle-symbol with the line in it?
    If this happens what other way is there to completely clear the console?

  3. Typing simply “a” and hitting return the console says “true”. The same happens with the letter “b”. But when I hit return after adding “c” (or any letter after that) the console displays an error? Why is “a” and “b” accepted but all following letters are not?

1 Like
  1. = is an assignment operator, so 10=9 is literally saying “assign 9 to 10” which makes no sense. To do an equality check, you should use == or ===. (=== is a bit more strict and it’s a good habit to use over ==. For example 0=="0" is true, while 0==="0" is false. You can read more at https://codeburst.io/javascript-double-equals-vs-triple-equals-61d4ce5a121a)
  2. I am not sure what you mean by this question. The symbol that you describe should clear the whole console. You can also use clear()
  3. Do you mean "a"(with quotes) or a? The first case should return “a”. The second case should show an error. EXCEPT when a variable named a or b is previously defined

I hope this clears things up. Could you otherwise provide a code snippet/photo/video as example?

2 Likes

Thanks Erno - that was very quick :0)

  1. of course ! I should have know that - and thanks for the link -
  2. the command: clear () helped - that’s great - - I assume the remainder I had was an error.
  3. I was referring to stating letters with no quotes. I get this sequence of responses from the console for a through c: - not what you get though - shouldn’t this be the same for all consoles?
1 Like

Not necessarily. The console is not a stand-alone interface, in fact it is connected to the website that you’re currently on. In this case, it can be the case that a script on the website, or one of the libraries that are being used, is assigning the variable a or b to true. Or you might have assigned I’m not sure but that is something that might be happening here.

For example if you open the console on this forum and type moment() you get access to a function (from the library MomentJs, which is a date formatter). If you type the same moment() on another website, it might throw an error.

So the way the console is executing the code is (almost) always the same. The data that it is using differs, depending on what has been stored.

2 Likes

That 's very interesting and revealing. Thanks again.
Gives me some more clues for more testing.

1 Like

Hi @yestome,

One way to stop this kind of interference is to load a blank page in your browser with the URI about:blank

When you clear your console, any variables you’ve previously defined are still stored. I think this may be what is happening with your a's b's and c's.
If you had previously assigned true to a and c etc. then this is why the console is returning true when you enter these variable names, even after you’ve cleared the console. To check this, you should reload the whole page. This will wipe any stored variables and should give you the errors that @Erno mentioned earlier.

I hope your testing is going well! You’ll learn loads by having this kind of analytical mindset. Just don’t drive yourself mad in the process. You’ll find loads of these types of questions cropping up when you first start programming and using these tools. A lot of them “answer themselves” over time, so with some of them just be content to “log them” as queries, and you’ll find yourself “crossing them off” your mental list in no time :grin:

1 Like

yes that is totally correct - thanks Jon - makes total sense and was very helpful!

That is a comforting preview of how many doubts will dissolve over time - thank you
I’ll do that as much as my confusion allows me to ;O)

1 Like

I know it’s sometimes hard to let things lie, especially if you are someone who likes to get to the bottom of things — believe me, I know… because I’m like that :wink:

But, yes, my own personal experience is that quite a lot of these loose ends do just suddenly decide to “reveal their inner secrets” somewhere further down the line…and those are very satisfying moments :slightly_smiling_face:

But don’t get me wrong…some do require hours of research and persistent questioning of others until you have an answer that makes sense to you — the key thing here being that what makes sense to others doesn’t necessarily make sense to you in the same way.

1 Like

Thank you Jon for further comments and tips.

1 Like