javascript : Object.isDate
javascript : Object.isDate
Target:
Applicable with any javascript Object Variable that holds date value .
Description :
When an object holds an date then it return true otherwise undefined. basically it is defined in Date prototype. Many time in programming we face a problem that an object variable holds Date value or other object structure then it help us. Before writing the code of Date manipulation we can check whether a variable holds Date value or not.
Note: It is an property of Date, that is defined in Date Prototype.
It is useful to check an object variable is Date or any other type.
When we check the typeof(object_variable) it return 'object' not 'date'.
Syntax:
Object.isDate
return true when object hold's Date value otherwise undefined
Usase:
- var obj = 'date';
if(obj.isDate){
console.log('Object holds date value');
}
else{
console.log('Object is not a date value');
}
It return "Object is not a date value". - var obj = '1/Jan/2021';
if(obj.isDate){
console.log('Object holds date value');
}
else{
console.log('Object is not a date value');
}
It return "Object is not a date value". - var obj = '1/Jan/2021'.toDateTime();
if(obj.isDate){
console.log('Object holds date value');
}
else{
console.log('Object is not a date value');
}
It return "Object holds date value". - var obj = '1/Jan/2021'.toDate();
if(obj.isDate){
console.log('Object holds date value');
}
else{
console.log('Object is not a date value');
}
It return "Object holds date value". - var obj = ''.toDate();
if(obj.isDate){
console.log('Object holds date value');
}
else{
console.log('Object is not a date value');
}
It return "Object holds date value". - var obj = new Date();
if(obj.isDate){
console.log('Object holds date value');
}
else{
console.log('Object is not a date value');
}
It return "Object holds date value".
Download MYJS.js
Comments
Post a Comment