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:

  1. 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".
  2. 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".
  3. 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".
  4. 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".
  5. 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".
  6. 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

MyJs is a collection of java script extension methods that enhances the JavaScript objects, class object, DOM element, domElementsCollections, Date, String, Number and other data type. 

Include in you project landing page (master page) and it will extends your DOM and JavaScript Objects.

Comments

Popular posts from this blog

javascript : String.right

javascript : String.left

javascript : .nextAll()