November 2017
Intermediate to advanced
386 pages
9h 22m
English
This idea of defining a function on the run, also allows us to write polyfills that provide otherwise missing functions. For example, let's say that instead of writing code like:
if (currentName.indexOf("Mr.") !== -1) { // it's a man ...}
You'd very much prefer using the newer, clearer way, and just write:
if (currentName.includes("Mr.")) { // it's a man ...}
What happens if your browser doesn't provide .includes()? Once again, we can define the appropriate function on the run, but only if needed. If .includes() is available, you need do nothing, but if it is missing, you then define a polyfill that will provide the very same workings.