Special statement
This article is a series by Tomek Sułkowski published on Medium. The copyright belongs to the original author.
I have sent the translation links of the first two articles to the author himself, although he does not understand Chinese, he is still very happy haha, we also brought foreign friends to Nuggets, haha, screenshots at the end
The translator had already communicated with the author before the translation to get permission to translate the whole series. In order not to disturb your reading, the record of authorization is here
The body of the
In the 24 days leading up to the holiday season, I will be publishing a series of short articles on how to use development tools in a more interesting way. Yesterday we reached number eight, so today we’ll start with number nine:
9. console.assert
MDN-console/assert
When the first argument we pass in is false, console.assert prints the value that follows it. This is useful when you need to print something in a special case – now you can do it without using an if expression. In addition, you can get a stack trace for nothing; -)
Please note that if you are using NodeJS version 10.0 or less, this may interrupt the execution of the following code, but it was fixed in the.10 version (of course, it is completely safe to use in the browser).
10. console.table
Surprisingly, this tip is not widely known among developers. If you have an array (or an array-like object, or just an object), you can use the console.table method to print it out as a nice table. Not only does it calculate the column names based on all the properties of the objects in the array, but the columns are scalable and even… Ordering! 😳
When there are too many columns, you can use the second argument to pass in only the column names you want to display.
Console. table will only work if node versions are 10 or older if you occasionally try it in the background
11. console.dir
The most popular console.log method prints the data in formatted form, and the default formatting is useful in most cases. But sometimes that’s not what you want to see – the most typical example is when you want to print a DOM node.
Console. log will render the interactive element as if it were clipped from Elements. What if you wanted to see the actual JavaScript object that this node is associated with? And want to see his properties and so on?
In such cases, if you need a more direct representation of the data, you can use console.dir.
That’s it for today, routine: If you learn something new from it
→ Follow me on Twitter Tomek Sułkowski
Other series
Other articles in this series will be translated soon, with links posted here.
- Day 1: ‘$’ in the Console
- Tips you might not know about Chrome debugging tools Day 2: Copying & Saving
- Chrome debugging tools you didn’t know about
- The Chrome debugging tool has a few tricks you don’t know about.
- Day 5: Console log, puzzling case
- You don’t know the Command menu for Chrome
- 7. Fun tips you didn’t know about the Chrome Debugging Tool Consle
- Chrome’s Color picker is a Color picker that you don’t know about.
- Day 9: Time console
- Custom Formatters are custom formatters for Chrome.
- Today: Style Editors continued
- Tips you don’t know about the Chrome Debug Tool Day 12: Ninja Log Print! (the ninja logs)
- Chrome debugging Tool tips you didn’t know about
- Chrome Debugging Tool tips you didn’t know About day 14: Other shortcuts
- Chrome debugger tips you didn’t know about
- Tips you don’t know about Chrome debugging Tools 16: Breakpoints
- Day 17: Farewell to Console
- What you Didn’t know about Chrome Debug Tools
- Chrome debug tool tips you don’t know
- Tips you didn’t know about Chrome debugging tools Day 20: The dark arts of Workspace
- Tips you Don’t Know about Chrome Debugging Tools Day 21: Snippets
- Chrome Debugging Tool tips you didn’t know
- Chrome debug Tool tips you don’t know
- Day 24: The last day, New Year’s Day, is awesome
Write in the last
If you are sure of my translation, you can also pay attention to my wave oh ~ incidentally my open source project, for a wave of star→ see here, beautiful blog system