Linked list in JavaScript I wrote this simple linked list in JavaScript. Feedback is welcome.

function Node(data)
{
    this.next = null;
    this.data = data;
}

function LinkedList()
{
    this.length = 0;
    this.head = null;

    // add node with given value to the list.
    this.add = function (value)
    {
        var node = new Node(value);

        var temp;

        if(this.length == 0)
        {
            this.head = node;
            this.length++;
            return;
        }

        temp = this.head;

        // Move to the position where we can perform addition
        // This logic is slightly different when we for example need to do search.
        while(temp.next)
        {
            temp = temp.next;
        }

        temp.next = node;
        this.length++;

        return;

    }

    // Search for node with given value.
    this.search = function (value)
    {
        // index where the node was found
        var index = 0;

        // If the list is empty there is no point in searching.
        if(!this.head)
        {
            console.log("List is empty");
            return;

        }

        var temp = this.head;

        while(temp)
        {
            if(temp.data == value)
            {
                console.log("Found at: "  + index);
                return;
            }

            // move to next node
            temp = temp.next

            index++;
        }

        console.log("Node not found");

    }

    // Dump whole list
    this.print = function()
    {
        if(!this.head)
        {
            console.log("List is empty");
            return;

        }

        var temp = this.head;

        while(temp)
        {
            console.log(temp.data);
            temp = temp.next
        }

    }

    // Remove node at index. Index starts from 0.
    this.removeAtIndex = function (index)
    {
        var i = 0;

        if(index &lt; 0 || index &gt;= this.length)
            throw "Wrong index";

        var temp = this.head;

        if(!this.head)
            return;

        if(index == 0)
        {
            this.head = this.head.next;
            this.length--;
            return;
        }

        // Move to the position where we can perform delete.
        for(i = 0; i &lt; index  - 1; i++)
        {
            temp = temp.next;
        }

        temp.next = temp.next.next;
        this.length--;
        return;


    }
}

var x = new LinkedList();
x.add(200);
x.add(100);
x.add(300);
x.add(400);
x.print();
x.search(400);
x.removeAtIndex(2);
x.print();
x.search(400);
JavaScript has an array data type that acts like different data structures. It can be a list, a stack, or even a queue depending on how you use it. If this code is merely for learning purposes, then it's fine. Otherwise, try using available native data structures instead of reinventing them.

Now to your code. First off, I would suggest against using constructors and use basic object literals and functions instead. It is simpler to think of data simply as a structure of arrays and objects.

this.add


Very vague name. It's not clear whether we're adding a new node (where we pass in a new instance of Node) or adding a value (that the method will wrap for us, which it currently does). It's best if you make it more verbose, like addValue.

if(this.length == 0)


length is a function of the number of nodes in the list. A common problem I had in data structures class is if the length value was out of sync with the actual node count value. This made very interesting bugs when length and the actual node count didn't match up.

To get the length, it's better, although inefficient, to actually count the nodes present. Alternatively, a list without a head is essentially an empty list. if(!this.head) is sufficient to determine an empty list.

temp = this.head;
while(temp.next){
  temp = temp.next;
}


This can be extracted to a findTail function which can be really useful. Alternatively, keeping track of the tail like you're doing with head is also a convenient and more efficient way to do this. Not sure if there are standards to linked lists, but it's an optimization you can take advantage.

this.search = function (value){}


I don't really get the point of search. Is it supposed to just print a message if it exists? If it does, it's better named like printMessageIfValueExists. Otherwise, one would take it as a function that takes a value and returns a boolean representing its existence.

Also, a linked list best remain a data structure. It shouldn't handle printing as this makes it dependent on printing capabilities of the environment, an unnecessarily coupled dependency. Leave that to whatever code is using the linked list. Same goes for your print method.

this.removeAtIndex = function (index)


Again, another one of those vaguely-named functions. Why? It's because we're not sure what "remove" exactly means. It could mean removing the value or removing the node entirely. I see that it's removing a node, so it should be removeNodeAtIndex.