January 2020
Intermediate to advanced
470 pages
11h 13m
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 we had some code such as the following:
if (currentName.indexOf("Mr.") !== -1) { // it's a man ...}
Instead of this, you might very much prefer using the newer, clearer way of, and just write the following:
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 fly, but only if needed. If .includes() is available, you need to do nothing, but if it is missing, you need to define a polyfill that will provide the very same workings. The following code shows an ...
Read now
Unlock full access