??? #JavaScript tip: Reduce an array of constants into an object to save yourself a couple lines of code. I'm using linear interpolation here to create an array of x,y,z values from a location, destination, and the movement time. https://t.co/0wlocaJLWu
? TIP When using PurgeCSS with classes that get dynamically created via e.g. a JS-library, you can whitelist them right in your CSS file #laravel https://t.co/tU3ngY71X0
A handy little debugging trick you can use in javascript is throwing exceptions to provide descriptive error messages in the console.
throw new Error('hello world')
? You can take this one step further by throwing a variable directly (works with all datatypes)
#javascript #js https://t.co/BLm2L6A4Qp
? You can use `await https://t.co/Sf5vzB4BmY.estimate()` to get the quota and usage of persistent data for the current site https://t.co/G2I9IpXdu6
??? Tip: awaiting is an execution-blocking operation, as in the rest of the function won't execute until the awaited promise is resolved. Run promises concurrently by awaiting references to the already executed promises! (You can also do this with Promise.all()) https://t.co/Vp1C6pOXkJ
Here's a #javascript tip that I use every single day!
Instead of:
console.log('car', car);
console.log('book', book);
console.log('value', value);
You can do:
console.log({car, books, value});
? https://t.co/EusxwK9iW7
How to view your connection speed from DevTools:
> window.navigator.connection
- This is the "NetworkInformation API"
- It returns bandwidth, latency, & connection type approximations? https://t.co/nlCTIWiaTH
Type in Chrome console:
const obj = { }
Then type:
copy( obj );
Result:
const obj = { } will be copied to clipboard. Paste it into your text editor.
Works with any currently defined object.
Makes debugging a lot easier – used it 1000+ times @ work.
? When using JavaScript default function params, you can access other params from right inside the definition! https://t.co/aSA5m6E3hy
Prettify your JSON output ?
Tired of the one-liner JSON output, well no more! Utilize JSON.stringify built-in pretty printing. Set the 3rd parameter with your desired spacing level ? Bam, instant GLAM ✨
#100DaysOfCode #CodeNewbie #301DaysOfCode https://t.co/6VQgAHdTVT
Quick and easy way to check strings against a regex in Javascript
Define the pattern then test the desired string. Works like a charm! ❤ https://t.co/qML6YNUCcq
OMG.
I just learned how to write comments in a json file via @wesbos
#javascript #npm #nodejs #100DaysOfCode #301DaysOfCode https://t.co/ekOlP0o2fT
When everything you try to fix npm fails:
> npm-fresh https://t.co/JaTcIu8gaD
life hack: console log function that auto-indents based on the depth of your call stack https://t.co/6pYyOIKdb9
? If you are trying to debug something in the middle of chaining array methods, just map over it, console.log, and return it.
Since console.log returns nothing, it will just pass the entire array through.
You can even make a handle little debug function ? https://t.co/HCtLh4QYm6
Generate a random alpha-numeric string with the given length. ? #JavaScript https://t.co/sUB3KxWEVf
An easy way to get the first truthy value of an array in #javascript is passing Boolean to the find function. https://t.co/56J4LTNNJm
TIL:
`document.getElementsByClassName()` & Co return _live_ `NodeList`s.
`document.querySelectorAll()` returns a _static_ `NodeList`.
Use `querySelectorAll()`, people! https://t.co/s7aGuxMGgN
Hot tip ? Thanks to @wesbos and @stolinski for this gem I picked up from @syntaxfm. If you ever need to loop over an object in #javascript, take a look at the Object.entries method. So much more readable and so much less gnarly. https://t.co/xdY0Eg40cR
#webdev Learn something new everyday ??
No more messy RegEx to extract URL query/search parameters (interesting)
#javascript #CSS https://t.co/5k4C5OGIJ1