One other way to use the console api is to create a message for developers or hackers trying to execute code on your site. You may have seen this on sites like facebook and pinterest. These may create a fun way for coders to play with the code or highlight anything you want.
var bigStyle = 'color:red; font-size:60px; font-weight:bold; font-family:helvetica, sans-serif; text-shadow: 1px 1px 2px black;'
console.log('%c Big Text', bigStyle)
In the above example we’ve used two “%c” reference to reference two colors for the different style for two words. You can even try to use the stylesheet right in the console.log function but it would make it for a messy code which may be hard to control. Which is why it’s added to the bigStyle variable. If you were to use it without the bigStyle variable it would be
console.log('%c Big Text', 'color:red; font-size:60px; font-weight:bold; font-family:helvetica, sans-serif; text-shadow: 1px 1px 2px black;');
While you may have reduced the text required for the code to work, it makes it more clunky and prone to mistake if you were to add more style to the text.
Let us know what you think in the comments.
Category: Cool Hacks