JavaScript Tip 💡
You can use Object.entries() to iterate through the properties of an object and access both key and value.
No need to do an object lookup for each iteration.
#Javascripttip
You can use Object.entries() to iterate through the properties of an object and access both key and value.
No need to do an object lookup for each iteration.
#Javascripttip
JavaScript Tip 💡
Did you know that JSON.stringify takes a replacer function as its second argument?
You can use it to do filter and replace values when stringifying an object.
#Javascripttip
Did you know that JSON.stringify takes a replacer function as its second argument?
You can use it to do filter and replace values when stringifying an object.
#Javascripttip
JavaScript Tip 💡
Use the property
Here's an example in React
#Javascripttip #Reacttip
Use the property
valueAsNumber
to get the numeric number from an input field through an event.Here's an example in React
#Javascripttip #Reacttip
JavaScript Tip 💡
Instead of using find(), or manually searching a list for an occurrence, use the array method some() instead.
It’s built for exactly that purpose.
#Javascripttip
Instead of using find(), or manually searching a list for an occurrence, use the array method some() instead.
It’s built for exactly that purpose.
#Javascripttip
JavaScript Tip 💡
Did you know that you can cancel a fetch request using an AbortController?
A common use-case is React:
If a component unmounts while a fetch call is awaited, it can be useful to abort the call.
#Javascripttip #Reacttip
Did you know that you can cancel a fetch request using an AbortController?
A common use-case is React:
If a component unmounts while a fetch call is awaited, it can be useful to abort the call.
#Javascripttip #Reacttip
JavaScript Tip 💡
In JavaScript, there are no classes.
It’s syntactical sugar added to please developers from other languages such as Java or C#.
Most of the time you can avoid using them altogether. Try.
Instead, use modules.
#Javascripttip
In JavaScript, there are no classes.
It’s syntactical sugar added to please developers from other languages such as Java or C#.
Most of the time you can avoid using them altogether. Try.
Instead, use modules.
#Javascripttip
JavaScript Tip 💡
Use the spread operator to create shallow copies of objects and arrays.
It's way cleaner than iterating and manually copying over.
#Javascripttip
Use the spread operator to create shallow copies of objects and arrays.
It's way cleaner than iterating and manually copying over.
#Javascripttip
JavaScript Tip 💡
Use console.trace instead of console.log.
It will show you the complete call stack when debugging.
#Javascripttip
Use console.trace instead of console.log.
It will show you the complete call stack when debugging.
#Javascripttip
Forwarded from Learn JavaScript™