Difference between == (Equality) and === (Identity) in JavaScript:

In JavaScript we can use Equality (==) and Identity (===) operators to compare 2 operands for equality. 

Equality Operator (==)

Identity Operator (===)

It is called Equality operator

It is called Identity operator

It will do type conversion before comparing the operands

It will not convert to any type

So the operands need NOT to be of same type as it do conversion

Both operands should be of same type

Eg. 1 == “1” results true

Eg. 1 === “1” results false

Eg. 1 == true results true

Eg. 1 === true results false


  1. NULL and UNDEFINED are equal when using Equality operator. ie. NULL == UNDEFINED results true. But NULL === UNDEFINED results false
  2. Also “true” and true are not equal for both operators. ie. “true” == true and “true” === true results false
  3. Also NaN == NaN and NaN === NaN results false

Consume API custom function from JQuery

In MVC4 Web API project, I added a API Controller and tried to consume that from jQuery. Initially I am able to consume where I haven’t written any custom action(function) in API Controller.
Then I added a custom action(GetTemplate). See below the code.
public class CollectionController : ApiController
        public List<string> GetTemplate()
            return new List<string>() { “ABC”, “DEF” };

My jQuery Code:
            cache: false,
            type: ‘GET’,
            datatype: ‘json’,
            url: ‘../../api/Collection/GetTemplate’,
            contentType: “application/json;charset=utf-8”,
            success: function (result) {
            error: function (xhr, status, error) {

While trying to consume this I was getting the following error.
{“Message”:”No HTTP resource was found that matches the request URI
“MessageDetail”:”No action was found on the controller ‘Collection’ that matches the request.”}

Then I have commented the default routing in WebApiConfig file and added the following coding.
public static class WebApiConfig
        public static void Register(HttpConfiguration config)

            // By Adding this we can have Custom Action in API and call it using Action Name
                name: “Action”,
                routeTemplate: “api/{controller}/{action}”

            /*  config.Routes.MapHttpRoute(
                 name: “DefaultApi”,
                 routeTemplate: “api/{controller}/{id}”,
                 defaults: new { id = RouteParameter.Optional }

After modifying the WebApiConfig file as above it worked for me. Now I am able to consume the API custom action from jQuery.

Remove li from ul

In last post we discussed about adding li to ul dynamically using jQuery. Now in this post we can see what are the possible ways to remove the li from ul. Below is the sample HTML code.

<input type=”button” id=”AddLI” value=”Add List to UL” />

<input type=”button” id=”remove-all” value=”Remove All” />

<input type=”button” id=”remove” value=”Remove except First and Second” />

<input type=”button” id=”remove2″ value=”Remove Only First and Second” />

<ul id=”ul-sample”>


In the above code we have four buttons which can add li dynamically, remove all li from ul, remove all li except first and last child and remove only first and last child.

Remove All LI from the UL:-

If we want to remove all the li from a particular ul, then there is two ways to achieve that. First one is to remove all the li through below code

//Removing All li from ul
    $(‘#remove-all’).click(function () {

        $(‘ul#ul-sample’).empty(); // Method 1 Make ul empty

        $(‘ul#ul-sample li’).remove(); // Method 2 Removes All li


In the above code there are two methods to remove li. We can use either of these.

Second one is to remove all li by looping through all li. This method will be useful when we needs to remove only some particular li’s specifically. For example by checking li values or by elements present within li. Below is the code for that

 //Removing All li from ul
    $(‘#remove-all’).click(function () {

        $(‘ul#ul-sample li’).each(function () { // loops through all li
            $(this).remove(); // Remove li one by one


Remove All LI from the UL Except First and Last:-

//Removing All li from ul except first and last
    $(‘#remove’).click(function () {       

        $(‘ul#ul-sample li:not(:first):not(:last)’).remove();


Remove Only First and Last li of ul:-

//Removing only first and last li from ul
    $(‘#remove2’).click(function () {

        $(‘ul#ul-sample > :last-child, ul#ul-sample > :first-child’).remove();