whatisthis?

javaScript. console ๊ฐ์ฒด์˜ ๋ฉ”์„œ๋“œ ๋ณธ๋ฌธ

WEB STUDY/JAVASCRIPT

javaScript. console ๊ฐ์ฒด์˜ ๋ฉ”์„œ๋“œ

thisisyjin 2022. 1. 19. 12:43

๐ŸŸจ console ๊ฐ์ฒด์˜ ๋ฉ”์„œ๋“œ 

- log

- dir

- count

- time

- timeEnd

 


 

 

 

 

๐Ÿ“Œ console.log()

 

Web Console์— ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋Š” console.log๋Š”

๊ฐ์ฒด / ๋ฌธ์ž์—ด / ์น˜ํ™˜๋ฌธ์ž์—ด ๋“ฑ์„ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค.

 

+) ๋กœ๊น… ๋””์ž์ธ์— ๋”ฐ๋ผ info / warn / error ๋„ ์กด์žฌํ•œ๋‹ค.

 

 

___

 

 

๐Ÿ“Œ console.dir()

๊ฐ์ฒด๋Š” dir๋กœ , ๋‚˜๋จธ์ง€๋Š” log๋กœ ๋กœ๊น…ํ•˜๋ฉด ํŽธํ•˜๋‹ค.

console.dir(document.body);

 

>>> โ” console.dir() ๊ณผ์˜ ์ฐจ์ด์ ์€ ๋ฌด์—‡์ผ๊นŒ?

- DOM ์š”์†Œ๋“ค์„ console๋กœ ๋ณด๋‚ผ ๋–„ ์ฐจ์ด์ ์ด ์žˆ๋‹ค.

console.log - element๋ฅผ HTML๊ณผ ๊ฐ™์€ ํŠธ๋ฆฌ๊ตฌ์กฐ๋กœ ์ถœ๋ ฅ.
>> DOM์š”์†Œ์— ๋Œ€ํ•ด ํŠน๋ณ„ ์ฒ˜๋ฆฌ ์ œ๊ณต

- ๊ฐ์ฒด๋ฅผ ๋กœ๊น…ํ•˜๋ฉด โŒ
console.dir - element๋ฅผ JSON๊ณผ ๊ฐ™์€ ํŠธ๋ฆฌ๊ตฌ์กฐ๋กœ ์ถœ๋ ฅ 

- ๊ฐ์ฒด ๋กœ๊น… โญ•

 

- console.log๋กœ ๊ฐ์ฒด๋ฅผ ๋กœ๊น…ํ•˜๋ฉด, ๊ฐ’์ด ๊ฐฑ์‹ ๋  ๋•Œ๋งˆ๋‹ค ๋Š์ž„์—†์ด ๋ฐ”๋€ ๊ฐ’์œผ๋กœ ๋ณด์—ฌ์ค€๋‹ค.

๋”ฐ๋ผ์„œ, ๊ฐ์ฒด๋ฅผ ๋กœ๊น…ํ•˜๋Š”๊ฒƒ์€ ๊ถŒ์žฅX.

 

 

์—ฌ๊ธฐ์„œ, ๊ฐ์ฒด(Object)์—๋Š”
ํ•จ์ˆ˜, ๋ฐฐ์—ด, ๊ฐ์ฒด ๋ชจ๋‘ ํฌํ•จ๋œ๋‹ค.
์ฆ‰, ๋‚ด์šฉ๋ฌผ์ด ๋ณ€ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ ๋ชจ๋‘ console.log๋กœ ๋กœ๊น…ํ•ด์„  โŒ

 

 

___

 

 

๐Ÿ“Œ console.count()

- ๋ช‡ ๋ฒˆ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ๋กœ๊ทธํ•  ์ˆ˜ ์žˆ์Œ. ( count() ํ˜ธ์ถœ์˜ ํšŸ์ˆ˜๋ฅผ ์„ธ์–ด ์ถœ๋ ฅ )

- ์ธ์ž(argument) = ์นด์šดํ„ฐ์˜ ์ด๋ฆ„. (Label)

 

>> ๋ ˆ์ด๋ธ” ๋ช…์‹œ ์•ˆํ•˜๋ฉด default๋กœ ๋‚˜ํƒ€๋‚จ.

 

let user = "";

function greet() {
  console.count(user);
  return "hi " + user;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count("alice");

 

 

___

 

 

๐Ÿ“Œ console.time() / console.timeEnd()

console.time('ํƒ€์ด๋จธ');
// ๋‚ด์šฉ 
console.timeEnd('ํƒ€์ด๋จธ'); // ํƒ€์ด๋จธ: 3.259083490ms

 

time๊ณผ timeEnd์— ๊ฐ™์€ ํƒ€์ด๋จธ ์ด๋ฆ„์„ ์ฃผ์–ด์•ผ ์ •์ƒ์ž‘๋™ํ•จ.

- ์ฝ”๋“œ ์ˆ˜ํ–‰ ์‹œ๊ฐ„ ํ™•์ธ

 

 

 

 

 

 

 

 


 

 

REFERENCE

 

Console.log() - Web API | MDN

Web Console์— ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

developer.mozilla.org

 

console.count() - Web API | MDN

console.count() ๋ฉ”์„œ๋“œ๋Š” ํŠน์ • count() ํ˜ธ์ถœ์˜ ํšŸ์ˆ˜๋ฅผ ์„ธ์–ด ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

developer.mozilla.org