This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Chris Steib
over 11 years

print vs. console.log

Not sure if this is a glitch or what, but when I run this simple “greet” function using a print command instead of a console.log command, it prints the variable twice.

var greeting = "Ahoy";
var greet = function (){;
print(greeting)
};
greet();

But if I run it with console.log, it just prints “Ahoy” once.

var greeting = "Ahoy";
var greet = function (){;
console.log(greeting)
};
greet();

What’s the difference? Why would it do that?

Answer 50812c728643780200002e7a

3 votes

Permalink

JavaScript does not have a print method – when I try it in Google Chrome’s, Opera’s or Firefox’s Developer console, it opens the print dialog, you know, the one for sending a Web page to a physical printer.

So the correct way of solving this is definitely your latter example.

points
Submitted by Alex J
over 11 years