Last active
September 22, 2016 08:14
-
-
Save kovaldn/5821801 to your computer and use it in GitHub Desktop.
Javascript: typeof & $.type()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // typeof | |
| // Знает: | |
| // 1) number | |
| // 2) string | |
| // 3) boolean | |
| // 4) undefined | |
| // 5) object | |
| // 6) function | |
| // Numbers | |
| typeof 37 === 'number'; | |
| typeof Infinity === 'number'; | |
| typeof NaN === 'number'; // Despite being "Not-A-Number" | |
| // Strings | |
| typeof "" === 'string'; | |
| typeof "bla" === 'string'; | |
| // Booleans | |
| typeof true === 'boolean'; | |
| typeof false === 'boolean'; | |
| // Undefined | |
| typeof undefined === 'undefined'; | |
| typeof blabla === 'undefined'; // an undefined variable | |
| // Objects | |
| typeof {a:1} === 'object'; | |
| typeof null === 'object'; // this is confusing! | |
| // Functions | |
| typeof function(){} === 'function'; | |
| // ЛУЧШЕ ИСПОЛЬЗОВАТЬ JQUERY | |
| // знает также: | |
| // 7) date | |
| // 8) regexp | |
| // 9) array | |
| $.type(el) | |
| $.type(true) === "boolean" | |
| $.type(3) === "number" | |
| $.type("test") === "string" | |
| $.type(function(){}) === "function" | |
| $.type([]) === "array" | |
| $.type(new Date()) === "date" | |
| $.type(/test/) === "regexp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment