This is a border issue, but I decided it was worth it. Below is the most concise way to check if underscore.js is loaded , and if there are any return paths for this approach.
typeof _ == "function" ? console.log('yes') : console.log('no');
Honestly, my "real" question is this. This is mainly a plugin that will be used on many front-end platforms. Some will underscore, and some will not. To make it universal and use the methods provided underscore, I want to check underscoreand provide a backup, if not, when choosing to use, when I can.
Is this a bad practice, and I should not even worry about using underscores when it is present?
NOTE. Unfortunately, lodash.jsthis is not an option, because I stupidly remade it underscore.jsinto the configuration require, and people do not seem to understand the need for AMD-compatible modules.
source
share