Console ơi mình đi đâu thế?

Console ơi mình đi đâu thế?

Nếu bạn là developer chắc hẳn bạn cũng không xa lạ gì với console. Nó là thứ hữu dụng để phát hiện lỗi trong browser console.

Để xem được tất cả api console bạn sử dụng câu lệnh window.console

https://i.imgur.com/x60fya6.png

Trong console.log() chúng ta có thể thay thế form như sau:

  • %o / %O - for objects;
  • %d / %i - for integers;
  • %s - for strings;
  • %f - for floating-point numbers;

console.log("Object value: %o with string substitution", {string: "str", number: 10});
Object string

Một số hàm phổ biến

  • console.log Black color text with no icon
  • console.info Blue color text with icon
  • console.debug Pure black color text
  • console.warn Yellow color text with icon
  • console.error Red Color text with icon

var playerOne = 120;
var playerTwo = 130;
var playerThree = 140;
var playerFour = 150;
var playerFive = 160;

console.log("Console.log" + " " +  playerOne);
console.debug("Console.debug" + " " +playerTwo);
console.warn("Console.warn" + " " + playerThree);
console.info("Console.info" + " " + playerFour);
console.error("Console.error" + " " + playerFive);
Hàm phổ biến trong console

CSS trong console.log

Điểm đặc biệt hơn là bạn có thể CSS trực tiếp trong console.log()


console.log("CSS %cLamsaodecode%c log!", "color: red", "color: green; font-size: 20px");
CSS in Console.log()
Tác giả: Jos Hoàng Tiên
Hãy mua cho mình một cuốn notebook và một cây bút kể cả khi bạn là dân coder.