Skip to content

Commit

Permalink
road: console.dir도 활용해보기
Browse files Browse the repository at this point in the history
  • Loading branch information
jgjgill committed Oct 23, 2024
1 parent b404eb3 commit 572278f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions roads/2024/10/23.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: 'console.dir도 활용해보기'
date: '2024-10-23'
slug: '2024-10-23'
type: 'road'
---

출근길에 본 재밌는 잡기술을 알게 되어 기록해본다.

<br />

보통 디버깅할 때 콘솔을 굉장히 많이 찍어본다.

간혹 뎁스가 깊은 데이터의 경우 콘솔에 `[Object]` 로 나와서 **사소한 불편함**을 느끼곤 했다.

이때 `console.dir`를 활용해볼 수 있다.

```ts
const obj = {
a: {
b: {
c: {
d: {
e: 100000000,
},
},
},
},
}

console.log(obj) // { a: { b: { c: [Object] } } }

console.dir(obj, {
depth: Infinity, // 데이터의 depth
colors: true, // 콘솔 색상
numericSeparator: true, // 숫자 가독성(_ 추가)
})
```

<Image
src="https://raw.githubusercontent.com/jgjgill/blog/main/roads/images/console-dir.png"
alt="console.dir 예시"
/>

## 참고 문서

- [Going weirdly deep on console.log](https://www.youtube.com/watch?v=Ozg5UqaD5fg)
Binary file added roads/images/console-dir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 572278f

Please sign in to comment.