Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view the data types of JavaScript variables

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to view the data types of JavaScript variables", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to view the data types of JavaScript variables" bar!

Typeof operator

You can use the typeof operator to view the data type of the JavaScript variable.

Example

Typeof "John" / / returns string

Typeof 3.14 / / returns number

Typeof NaN / / returns number

Typeof false / / returns boolean

Typeof [1, 2, 3, 4] / / return to object

Typeof {name:'John', age:34} / / returns object

Typeof new Date () / / returns object

Typeof function () {} / / returns function

Typeof myCar / / returns undefined (if myCar does not declare)

Typeof null / / returns object

Please note:

The data type of NaN is number

The data type of the Array is object

The data type of date (Date) is object

The data type of null is object

The data type of the undefined variable is undefined

If the object is JavaScriptArray or JavaScriptDate, we cannot determine their type by typeof, because they all return object.

Thank you for your reading, the above is the content of "how to view the data types of JavaScript variables". After the study of this article, I believe you have a deeper understanding of how to view the data types of JavaScript variables, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report