javascript : Object .isString

 

javascript : Object .isString


Target:

Applicable with any javascript Object Variable that holds string value .


Description :

When an object holds an string value then it return true otherwise undefined . basically it is defined in String prototype. Many time in programming we face a problem that an object variable holds String value or other object structure then it help us. Before writing the code of String manipulation we can check whether a variable holds String value or not.


Note: It is an property of String, that is defined in String Prototype.
It is useful to check an object variable is String or any other type.

another way to check variable holds string value is "typeof(variable) == 'string'"



Syntax:

ObjectVariable .isString

return true when object hold's String value otherwise undefined


Usase:

  1. var obj = 'abcd';
    console.log('typeof obj = ' + typeof(obj));
    if(obj.isString){
         console.log('Object holds String value');
    }
    else{
         console.log('Object is not a string');
    }
    It return
    "typeof obj = string"
    "Object holds String value" .
  2. var obj = '55';
    console.log('typeof obj = ' + typeof(obj));
    if(obj.isString){
         console.log('Object holds String value');
    }
    else{
         console.log('Object is not a string');
    }
    It return
    "typeof obj = string"
    "Object holds String value" .
  3. var obj = 55;
    console.log('typeof obj = ' + typeof(obj));
    if(obj.isString){
         console.log('Object holds String value');
    }
    else{
         console.log('Object is not a string');
    }
    It return
    "typeof obj = number"
    "Object is not a string" .
  4. var obj = [55];
    console.log('typeof obj = ' + typeof(obj));
    if(obj.isString){
         console.log('Object holds String value');
    }
    else{
         console.log('Object is not a string');
    }
    It return
    "typeof obj = object"
    "Object is not a string" .


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()