Skip to content

Commit

Permalink
Add console logging tips
Browse files Browse the repository at this point in the history
  • Loading branch information
zackhall committed Feb 26, 2016
1 parent 8eb6631 commit 5b530b5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions _posts/en/2016-xx-xx-helpful-console-log-hacks.md
Original file line number Diff line number Diff line change
@@ -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 + '');
```

0 comments on commit 5b530b5

Please sign in to comment.