en.javascript.info/1-js/7-js-misc/1-class-instanceof/1-format-date-polymorphic/solution.md
2015-03-22 00:36:11 +03:00

15 lines
No EOL
737 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Для определения примитивного типа строка/число подойдет оператор [typeof](#type-typeof).
Примеры его работы:
```js
//+ run
alert( typeof 123 ); // "number"
alert( typeof "строка" ); // "string"
alert( typeof new Date() ); // "object"
alert( typeof [] ); // "object"
```
Оператор `typeof` не умеет различать разные типы объектов, они для него все на одно лицо: `"object"`. Поэтому он не сможет отличить `Date` от `Array`.
Для отличия `Array` используем вызов `Array.isArray`. Если он неверен, значит у нас дата.