Underscore.js is a javascript library that is capable enough to handle arrays, strings, objects, map, set very easily and efficiently. The _.isDate() function in underscore.js is used to tell if the given object is a date object or not.
Syntax:
_.isDate(object);
Parameters: It takes only one parameter i.e the object.
Return: This function returns a boolean value. The value is true is the object is date object else it is false.
Note: Please Link the underscore CDN before using this code directly in the browser through the code.
Example 1:
<!DOCTYPE html> < html > < head > < script src = </ script > </ head > < body > < script > let date=new Date() let str="9/9/9"; console.log(_.isDate(date)); console.log(_.isDate(str)); </ script > </ body > </ html > |
Output:
Example 2:
<!DOCTYPE html> < html > < head > < script src = </ script > </ head > < body > < script > let date1=new Date(); let date2="09-jan-1888" let boolDate1=_.isDate(date1); let boolDate2=_.isDate(date2); if(boolDate1) console.log( `_.isDate function returns ${boolDate1} \n date is: ${date1}`) else console.log( `_.isDate function returns ${boolDate1} \n ${data1} is not a date object`) if(boolDate2) console.log( `_.isDate function returns ${boolDate2} \n date is ${date2}`) else console.log( `_.isDate function returns ${boolDate2} \n ${date2} is not a date object`) </ script > </ body > </ html > |
Output: