RTYX
RTYX

Reputation: 1334

Why does "clear()" work on Chrome's console, but not "log()"?

The console.clear() method clears the console if the console allows it. You can call it directly from Chrome's console by simply typing clear(), console.clear() or window.clear().

The console.log() method outputs a message to the web console. You cannot call it directly from Chrome's console by simply typing log(). You have to use console.log().

I would understand this if clear() was a method listed inside the window object pointing to the method in the console, but it isn't listed when logging console.log(window) or console.log(this) in the console.

Why is clear directly accessible but log not?

Upvotes: 0

Views: 33

Answers (1)

Bergi
Bergi

Reputation: 664548

You can call it directly from Chrome's console by simply typing clear(), but it's not a window method.

Yes, this clear() is part of the console utilities which are accessible only from the console itself. It's not part of the console object (MDN).

Upvotes: 2

Related Questions