Determine the data type of JavaScript

Source: Internet
Author: User
Tags cdata constructor

  This article is mainly to determine the JavaScript data type (sample code) for a detailed introduction, the need for friends can come to the reference, I hope to help you.

 1 determines whether the array type code is as follows: <strong><script type= "Text/javascript" > //<! [cdata[  var a=[0];  document.write (IsArray (a), ' <br/> ');  function IsArray (obj) {  return ( typeof obj== ' object ') &&obj.constructor==Array; } //]]>  </script></STRONG>   2 to determine if the string type code is as follows: <script type= "Text/javascript" > //<! [cdata[  document.write (isstring (' Test '), ' <br/> ');  document.write (isstring, ' <br/> ');   function isstring (str) {  return (typeof str== ' string ') &&str.constructor==String; } // ]]>  </script>   3 Determines whether the numeric type code is as follows: <script type= "Text/javascript" > //<! [cdata[  document.write (isnumber (' Test '), ' <br/> ');  document.write (isnumber, ' <br/> ');   function Isnumber (obj) {  return (typeof obj== ' number ') &&obj.constructor==Number; } // ]]>  </script>   4 judgment isNo is the date type code as follows: <script type= "Text/javascript" > //<! [cdata[  document.write (isDate (new Date), ' <br/> ');  document.write (IsDate (a), ' <br/> ');   function isDate (obj) {  return (typeof obj== ' object ') &&obj.constructor==Date; } //] >  </script>   5 determine if the function code is as follows: <script type= "Text/javascript" > //<! [cdata[  document.write (isfunction (function test () {}), ' <br/> ');  document.write (Isfunction (10), ' <br/> ');  function isfunction (obj) {  return (typeof obj== ' function ') &&obj.constructor== function; } //]]>  </script>   6 Determines whether the object code is as follows: <script type= "Text/javascript" > LineNum//<! [cdata[  document.write (IsObject (new Object), ' <br/> ');  document.write (IsObject), ' <br/ > ');  function IsObject (obj) {  return (typeof obj== ' object ') &&obj.constructor==Object; }  //]]>  </SCRipt>    
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.