- JavaScript
- CoffeeScript
- PHP
- Python
- COBOL (Beta)
- Haskell
- Ruby
- C#
- Rust
- TypeScript
- R (Beta)
- C++
- Clojure
- Julia (Beta)
- Go
- C
- λ Calculus (Beta)
- Scala
- Crystal
- Java
- Elixir
- NASM
- Groovy
- Kotlin
- OCaml (Beta)
- Swift
- Racket
- PowerShell (Beta)
- Reason (Beta)
- Dart
- Lua
- Factor (Beta)
- D (Beta)
- RISC-V (Beta)
Start training on this collection. Each time you skip or complete a kata you will be taken to the next kata in the series. Once you cycle through the items in the collection you will revert back to your normal training routine.
DescriptionEdit
Common gotchas in Javascript
In this collection we are dealing with the problems of null, falsy, undefined, and 0.
You might be hitting errors like:
TypeError: Cannot read property 'length' of undefined
Uncaught TypeError: undefined is not a function
TypeError: reduce of empty array with no initial value
And you will be thinking about questions like:
- How do I check length safely?
- How do I safely use reduce after a method like filter that has returned an empty array?
- How do I say 'or this', if the first doesn't exist?
- How do I set a default or fallback value?
- How is null safety handled in JavaScript?
Some tools you will need:
if(myVar && myVar.length)
.reduce((sum, value) => sum + value, 0)
||
function multiply(a, b = 1)
===
And some tools to know about, but might not be available on this platform: