8650 shaares
190 private links
190 private links
In js, asserts can be used with console.assert(<condition as expression>, error message)
It is great for prototyping or use defensive programming inside a function.
Assertions often come in pairs.
Whenever you assert something, think about which distant part of the code base relies on the assertion you just wrote, and add an equivalent assertion there.
This is worth doing even in the trivial case, where the two parties are a function and its caller.
But be on lookout for more interesting cases, where the two halves of an assertion pair are separated by different implementations, or a process and time boundary.