The
Recent validation of JavaScript data types has a new understanding that can be judged so simple and comprehensive.
We have customized methods such as Isstring,isnumber, IsDate, IsError, Isregexp, Isboolean, IsNull, isundefined, IsObject, etc. Now show yourself the JavaScript data type validation functions and test sets that you define:
The following is a detailed description of the data types of JavaScript, divided into six types of data, the need for friends can come to the reference, I hope to help you
1, to determine whether the array type
The 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 determining whether a string type
The 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 Determining whether a numeric type
The 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 Determine whether the date type
The code is as follows:
<script type= "Text/javascript" >
//<![ cdata[
document.write (isDate (new Date), ' <br/> ');
document.write (isDate), ' <br/> ';
function IsDate (obj) {return
(typeof obj== ' object ') &&obj.constructor==Date;
}
]]>
</script>
5 judge whether it is a function
The code is as follows:
<script type= "Text/javascript" >
//<![ cdata[
document.write (isfunction (function test () {}), ' <br/> ';
document.write (isfunction), ' <br/> ';
function Isfunction (obj) {return
(typeof obj== ' function ') &&obj.constructor==Function;
}
]]>
</script>
6 Determine whether or not an object
The 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>
I hope this article will help you learn about JavaScript programming.