Node.js' built-in `assert` isn't just for tests! It is also a concise way to handle "if condition isn't true, throw error", no extra `if` required.
Can even use Chai for extra syntactic sugar: masteringjs.io/tutorials/moc…#JavaScript#CodeNewbie
Node.js' built-in `assert` isn't just for tests! It is also a concise way to handle "if condition isn't true, throw error", no extra `if` required.
Can even use Chai for extra syntactic sugar: masteringjs.io/tutorials/moc…#JavaScript#CodeNewbie
Pro tip: `type: 'asset/source'` in Webpack lets you import selected files as plain text.
For example, with the below Webpack config, you can `import` CSS files to get the CSS file as a string
#JavaScript#CodeNewbie
JavaScript strings have a `contains()` method that checks if the string contains a substring.
But IE doesn't support `contains()`, so use `indexOf()` for frontend: masteringjs.io/tutorials/fun…
`indexOf()` was part of the first JavaScript spec in 1997!
#JavaScript#CodeNewbie
Pro tip: `eslint . --fix` makes ESLint try to fix any warnings and errors. Doesn't work for all ESLint rules, but can save you a lot of repetitive work.
Learn more 👉 masteringjs.io/tutorials/esl…#JavaScript#CodeNewbie
Pro tip: `eslint . --fix` makes ESLint try to fix any warnings and errors. Doesn't work for all ESLint rules, but can save you a lot of repetitive work.
Learn more 👉 masteringjs.io/tutorials/esl…#JavaScript#CodeNewbie
Switch/case statements are great when an early return is inelegant because you don't want to repeat a non-trivial `return`.
`break` breaks out of the switch statement 👍
masteringjs.io/tutorials/fun…#JavaScript#CodeNewbie
Pro tip: you can append CSS to your page by creating a `style` tag. Handy when loading styles using `import` or `require()` with Webpack
#JavaScript#CodeNewbie