Page 1 of 1

purpose of console.log

Posted: Thu Jun 14, 2018 12:16 pm
by matermultorum
I'm having trouble understanding the usefulness of console.log. The text mentions displaying typed out info and I can see that it functions differently than comments, but what does it do that comments don't? Maybe I don't understand what logging a message into the console means. Does it have benefits at a higher level that aren't as obvious at the level we are at? I also noticed that I get similar results no matter where I put the console.log statement in the following lines. When I invoke the function it says 678, when I switch console and the function I get 678 undefined (see below)

function iDoNot(){
return 678
}
undefined
console.log(iDoNot());
678
undefined
iDoNot(console.log);
678

Thanks in advance for looking at this!
Kendall

Re: purpose of console.log

Posted: Fri Jun 15, 2018 12:13 pm
by JeremyMoritz
Remember that console.log() is a function. Therefore, you could put logic inside it. If you put a comment

Code: Select all

// 6 + 5
You'll only see that. But if you use a function

Code: Select all

console.log(6+5);
It will log the result to the console.

The iDoNot() function you created here doesn't expect any arguments, so passing in the console.log (as you did in your last example) is just the same as calling it without passing anything into it.

If you don't fully understand this yet, just hang in there. The issue is only because these examples have been overly simplified. It will all make since in time, and you'll see the significant distinctions among comments, return statements of custom functions, and the console.log() function.

purpose of console log

Posted: Mon Sep 02, 2019 11:26 am
by BeJimmieSiz
Somewhere in your code you are looking up child windows via an ID, and the child windows do not exist. If you did not add such code, then it could be that you used code from somewhere else that used this technique

HTH

CE.