-
Notifications
You must be signed in to change notification settings - Fork 814
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
Why don't you use instanceof
for isDate
?
#340
Comments
isDate
?instanceof
for isDate
?
I think you can check that: https://stackoverflow.com/a/643827 "you can use the |
Lodash also returns |
Also jest can mess up the instanceof functionality. |
You should have said import _ from 'lodash'
console.log(_.isDate("random_string")) // false
console.log(_.isDate(new Date("random_string"))) // true, it's a Date, but invalid Note: if you want a code that check, you can check as writed on the stackoverflow link with something like Object.prototype.toString.call(a) === '[object Date]' && !isNaN(a) import _ from 'lodash'
const test = (a)=>{
console.log(
_.isDate(a),
a instanceof Date,
Object.prototype.toString.call(a) === '[object Date]',
Object.prototype.toString.call(a) === '[object Date]' && !isNaN(a)
)
}
test("random_string")
// false false false false
test(new Date('random_string'))
// false false false false
test(new Date())
// false false false true playground: https://playcode.io/lodash |
Here is example code:
The text was updated successfully, but these errors were encountered: