Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何只用两行代码实现判断js中所有数据类型 #59

Open
artdong opened this issue May 11, 2020 · 1 comment
Open

如何只用两行代码实现判断js中所有数据类型 #59

artdong opened this issue May 11, 2020 · 1 comment
Labels
js javascript

Comments

@artdong
Copy link
Collaborator

artdong commented May 11, 2020

No description provided.

@artdong
Copy link
Collaborator Author

artdong commented May 11, 2020

判断js数据类型最简方法

let _toString = Object.prototype.toString;

function getType (value) {return _toString.call(value).slice(8, -1)}
getType(); // "Undefined"
getType(''); // "String"
getType(1); // "Number"
getType(1n); // "BigInt"
getType(Symbol('uid')); // "Symbol"
getType(true); //"Boolean"
getType([]); //"Array"
getType({}); //"Object"
getType(null); //"Null"
getType(function(){}); //"Function"

@artdong artdong added the js javascript label Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js javascript
Projects
None yet
Development

No branches or pull requests

1 participant