Home > Web Front-end > JS Tutorial > body text

Javascript typeof usage_javascript tips

WBOY
Release: 2016-05-16 18:57:07
Original
1014 people have browsed it

if(document.mylist.length != "undefined" ) {} This usage is incorrect.
The correct one is if( typeof(document.mylist.length) != "undefined" ) {}
or if( !isNaN(document.mylist.length) ) {}
The operand of typeof is not defined, and the returned value is "undefined".
The operand is a number typeof(x) = "number"
String typeof (x) = "string"
Boolean typeof(x) = "boolean"
Object, array and null typeof(x) = "object"
Function typeof(x) = "function" typeof operator returns a string representing the data type of the expression.
Possible strings are: "number", "string", "boolean", "object", "function" and "undefined".
For example:
alert(typeof (123));//typeof(123) returns "number"
alert(typeof ("123"));//typeof("123") returns "string" "
typeof operator
returns a string representing the data type of the expression.
typeof[()expression[]] ;
expression parameter is any expression for which type information needs to be found.
Script Home www.jb51.net For more javascript information, please visit
Explanation
The typeof operator returns type information as a string. There are six possible return values ​​of typeof: "number," "string," "boolean," "object," "function," and "undefined."
The parentheses in the typeof syntax are optional.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!