JS is full of hidden features honestly. Just like all other languages, you can never master it completely.
Here I have packed 3 features that most of us don't know.
Remember, these may not be the best way to perform a task.
Check these and Comment below how many you knew 👇
1. You can add Style to Console Logs
You can actually pass a second parameter to console log method 😃. Check the example below from MDN.
console.log("This is %cMy stylish message", "color: yellow; font-style: italic; background-color: blue;padding: 2px")
Isn't that amazing?
You can use %c multiple times as well.
Check Documentation: https://developer.mozilla.org/en-US/docs/Web/API/console#outputting_text_to_the_console
2. You don't need to define parameters for a Function
I got this from a Stackoverflow question.
function myFunc() {
console.log(arguments[0])
}
myFunc(1) // 1
You can just use the arguments array-like object.
This may not be one of your most favourite feature but still, this is a feature many of us don't know! 😌
3. Quick Tricks to convert types
Maybe these are not the best way all time, but still useful
For example, you can quickly create a (kinda)unique id this way -
let id = +new Date
Isn't that beautiful? 👀
Conclusion 👊
Did you know all of these?
Comment below and let others know!
Please let me know if you have any suggestions.
Thanks for reading! 😇
Comments
Post a Comment