From 5b530b5bcf53118880ba5079329ccd8834b792c9 Mon Sep 17 00:00:00 2001 From: Zack Hall Date: Fri, 26 Feb 2016 11:10:21 -0800 Subject: [PATCH] Add console logging tips --- .../2016-xx-xx-helpful-console-log-hacks.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 _posts/en/2016-xx-xx-helpful-console-log-hacks.md diff --git a/_posts/en/2016-xx-xx-helpful-console-log-hacks.md b/_posts/en/2016-xx-xx-helpful-console-log-hacks.md new file mode 100644 index 00000000..2d9f668e --- /dev/null +++ b/_posts/en/2016-xx-xx-helpful-console-log-hacks.md @@ -0,0 +1,30 @@ +--- +layout: *post + +title: Helpful Console Logging Tricks +tip-number: xx +tip-username: zackhall +tip-username-profile: https://twitter.com/zthall +tip-tldr: Helpful logging techniques using coercion and conditonal breakpoints. + +categories: + - en +--- + +## Using conditional breakpoints to log data + +If you wanted to log to the console a value each time a function is called, you can use conditional break points to do this. Open up your dev tools, find the function where you'd like to log data to the console and set a breakpoint with the following condition: + +``` +console.log(data.value) && false +``` + +This always evaluates to false, so it will not pause the page thread when it's hit, but it will log data to the console. This can also be used to count how many times a function or callback is called. + +## Printing a function variable to console + +Have you ever logged a function variable to the console and weren't able to just view the function's code? The quickest way to see the function's code is to coerce it to a string using concatenation with an empty string. + +``` +console.log(funcVariable + ''); +``` \ No newline at end of file