Does console.log only execute when you use inspect on website?
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 |
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 '18 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 '18 at 3:30
add a comment |
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 '18 at 3:27
frostyfrosty
99211637
99211637
Different browsers are different, but Firefox and Chrome definitely obeyconsole.log()
calls when the console is not visible.
– Pointy
Nov 12 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 3:30
add a comment |
2 Answers
2
active
oldest
votes
Yes, console.log()
in your code will execute without the console open on the web page.
add a comment |
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',
autoActivateHeartbeat: false,
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
Yes, console.log()
in your code will execute without the console open on the web page.
add a comment |
Yes, console.log()
in your code will execute without the console open on the web page.
add a comment |
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 '18 at 3:29
BenBen
315
315
add a comment |
add a comment |
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 |
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 |
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 '18 at 3:33
CertainPerformanceCertainPerformance
77.6k143864
77.6k143864
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 '18 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 '18 at 3:30