Does console.log only execute when you use inspect on website?
up vote
0
down vote
favorite
I have a lot of console.log in my script, and I don't want them slowing my script down when I don't have the console open.
So my question is, do they execute when the console is closed? Because if they do I would have to comment them out, and then uncomment them every time I need to see them.
javascript console console.log userscripts
add a comment |
up vote
0
down vote
favorite
I have a lot of console.log in my script, and I don't want them slowing my script down when I don't have the console open.
So my question is, do they execute when the console is closed? Because if they do I would have to comment them out, and then uncomment them every time I need to see them.
javascript console console.log userscripts
Different browsers are different, but Firefox and Chrome definitely obeyconsole.log()
calls when the console is not visible.
– Pointy
Nov 12 at 3:28
@Pointy That unfortunate. So I would have to comment them out when I'm not using them to make my script run faster?
– frosty
Nov 12 at 3:30
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a lot of console.log in my script, and I don't want them slowing my script down when I don't have the console open.
So my question is, do they execute when the console is closed? Because if they do I would have to comment them out, and then uncomment them every time I need to see them.
javascript console console.log userscripts
I have a lot of console.log in my script, and I don't want them slowing my script down when I don't have the console open.
So my question is, do they execute when the console is closed? Because if they do I would have to comment them out, and then uncomment them every time I need to see them.
javascript console console.log userscripts
javascript console console.log userscripts
asked Nov 12 at 3:27
frosty
98411637
98411637
Different browsers are different, but Firefox and Chrome definitely obeyconsole.log()
calls when the console is not visible.
– Pointy
Nov 12 at 3:28
@Pointy That unfortunate. So I would have to comment them out when I'm not using them to make my script run faster?
– frosty
Nov 12 at 3:30
add a comment |
Different browsers are different, but Firefox and Chrome definitely obeyconsole.log()
calls when the console is not visible.
– Pointy
Nov 12 at 3:28
@Pointy That unfortunate. So I would have to comment them out when I'm not using them to make my script run faster?
– frosty
Nov 12 at 3:30
Different browsers are different, but Firefox and Chrome definitely obey
console.log()
calls when the console is not visible.– Pointy
Nov 12 at 3:28
Different browsers are different, but Firefox and Chrome definitely obey
console.log()
calls when the console is not visible.– Pointy
Nov 12 at 3:28
@Pointy That unfortunate. So I would have to comment them out when I'm not using them to make my script run faster?
– frosty
Nov 12 at 3:30
@Pointy That unfortunate. So I would have to comment them out when I'm not using them to make my script run faster?
– frosty
Nov 12 at 3:30
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Yes, console.log()
in your code will execute without the console open on the web page.
add a comment |
up vote
0
down vote
In all the browsers I know of, they do execute even while the console is closed - for example, try running the following code with the console closed, then open the console after 5 seconds, and you'll see that the console has indeed been populated with the text:
setInterval(() =>
console.log('log');
, 1000);
The performance impact of console.log
is next to nothing, but if you wanted an easy way to toggle between having console.log
calls print to the console, and do nothing, you can define a console
variable on the top level of your userscript that has a log
function which does nothing, thus shadowing window.console.log
inside the scope of your userscript:
const console = log: () => void 0 ;
console.log('foo');
To print to the console normally again, just comment out the const console...
line (or use a boolean variable doPrintToConsole
or something).
This will not prevent native page scripts from console.log
ging. (If you wanted to prevent native page scripts from doing so, overwrite window.console.log
instead);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255588%2fdoes-console-log-only-execute-when-you-use-inspect-on-website%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Yes, console.log()
in your code will execute without the console open on the web page.
add a comment |
up vote
0
down vote
Yes, console.log()
in your code will execute without the console open on the web page.
add a comment |
up vote
0
down vote
up vote
0
down vote
Yes, console.log()
in your code will execute without the console open on the web page.
Yes, console.log()
in your code will execute without the console open on the web page.
answered Nov 12 at 3:29
Ben
315
315
add a comment |
add a comment |
up vote
0
down vote
In all the browsers I know of, they do execute even while the console is closed - for example, try running the following code with the console closed, then open the console after 5 seconds, and you'll see that the console has indeed been populated with the text:
setInterval(() =>
console.log('log');
, 1000);
The performance impact of console.log
is next to nothing, but if you wanted an easy way to toggle between having console.log
calls print to the console, and do nothing, you can define a console
variable on the top level of your userscript that has a log
function which does nothing, thus shadowing window.console.log
inside the scope of your userscript:
const console = log: () => void 0 ;
console.log('foo');
To print to the console normally again, just comment out the const console...
line (or use a boolean variable doPrintToConsole
or something).
This will not prevent native page scripts from console.log
ging. (If you wanted to prevent native page scripts from doing so, overwrite window.console.log
instead);
add a comment |
up vote
0
down vote
In all the browsers I know of, they do execute even while the console is closed - for example, try running the following code with the console closed, then open the console after 5 seconds, and you'll see that the console has indeed been populated with the text:
setInterval(() =>
console.log('log');
, 1000);
The performance impact of console.log
is next to nothing, but if you wanted an easy way to toggle between having console.log
calls print to the console, and do nothing, you can define a console
variable on the top level of your userscript that has a log
function which does nothing, thus shadowing window.console.log
inside the scope of your userscript:
const console = log: () => void 0 ;
console.log('foo');
To print to the console normally again, just comment out the const console...
line (or use a boolean variable doPrintToConsole
or something).
This will not prevent native page scripts from console.log
ging. (If you wanted to prevent native page scripts from doing so, overwrite window.console.log
instead);
add a comment |
up vote
0
down vote
up vote
0
down vote
In all the browsers I know of, they do execute even while the console is closed - for example, try running the following code with the console closed, then open the console after 5 seconds, and you'll see that the console has indeed been populated with the text:
setInterval(() =>
console.log('log');
, 1000);
The performance impact of console.log
is next to nothing, but if you wanted an easy way to toggle between having console.log
calls print to the console, and do nothing, you can define a console
variable on the top level of your userscript that has a log
function which does nothing, thus shadowing window.console.log
inside the scope of your userscript:
const console = log: () => void 0 ;
console.log('foo');
To print to the console normally again, just comment out the const console...
line (or use a boolean variable doPrintToConsole
or something).
This will not prevent native page scripts from console.log
ging. (If you wanted to prevent native page scripts from doing so, overwrite window.console.log
instead);
In all the browsers I know of, they do execute even while the console is closed - for example, try running the following code with the console closed, then open the console after 5 seconds, and you'll see that the console has indeed been populated with the text:
setInterval(() =>
console.log('log');
, 1000);
The performance impact of console.log
is next to nothing, but if you wanted an easy way to toggle between having console.log
calls print to the console, and do nothing, you can define a console
variable on the top level of your userscript that has a log
function which does nothing, thus shadowing window.console.log
inside the scope of your userscript:
const console = log: () => void 0 ;
console.log('foo');
To print to the console normally again, just comment out the const console...
line (or use a boolean variable doPrintToConsole
or something).
This will not prevent native page scripts from console.log
ging. (If you wanted to prevent native page scripts from doing so, overwrite window.console.log
instead);
setInterval(() =>
console.log('log');
, 1000);
setInterval(() =>
console.log('log');
, 1000);
const console = log: () => void 0 ;
console.log('foo');
const console = log: () => void 0 ;
console.log('foo');
answered Nov 12 at 3:33
CertainPerformance
72.5k143453
72.5k143453
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255588%2fdoes-console-log-only-execute-when-you-use-inspect-on-website%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Different browsers are different, but Firefox and Chrome definitely obey
console.log()
calls when the console is not visible.– Pointy
Nov 12 at 3:28
@Pointy That unfortunate. So I would have to comment them out when I'm not using them to make my script run faster?
– frosty
Nov 12 at 3:30