Monday, August 29, 2016

Function 'Currying' in Javascript

Currying is when you break down a function that takes multiple arguments into a series of functions that take part of the arguments. Here's an example in JavaScript:
function add (a, b) {
  return a + b;

add(3, 4); returns 7
This is a function that takes two arguments, a and b, and returns their sum. We will now curry this function:
function add (a) {
  return function (b) {
    return a + b;
This is a function that takes one argument, a, and returns a function that takes another argument, b, and that function returns their sum.

var add3 = add(3);

The first statement returns 7, like the add(3, 4) statement. The second statement defines a new function called add3 that will add 3 to its argument. This is what some people may call a closure. The third statement uses the add3 operation to add 3 to 4, again producing 7 as a result

Thursday, October 30, 2014

getElementsByTagName Vs getElementsByName in javascript

Difference Between getElementsByTagName and getElementsByName in javascript :

If you see these methods (getElementsByTagName and  getElementsByName in javascript)in sudden we will bit confuse

in this article i am going to explain the exact different between those methods in detail

Suppose you have this HTML :
<input name="test" type="url">
You'd got it with

Thursday, August 21, 2014

Difference Between JSON and Javascript Object Literal Notation

JSON [Javascript Object Notation] Vs Javascript Object Literal Notation

The main differences:
  • The keys must be strings (i.e. enclosed in double quotes ") in JSON.
  • The values can be either:
    • a string
    • a number
    • an (JSON) object
    • an array
    • true
    • false
    • null

JSON Example :


    "users": [
            "id": 1,
            "websitename": "Webcodehelpers",
            "url": "www.webcodehelpers"
            "id": 2,
            "websitename": "SriSolutions",
            "url": ""

Javascript Object Literal Notation Example :

{ users: [ { id: "1", websitename: "Webcodehelpers", url: "www.webcodehelpers" }, { id: "2", websitename: "SriSolutions", url: "" } ] }

Tuesday, August 19, 2014

which of the following should you do to exit a loop immeadiately without finishing the cycle?

a)      You should code a key stroke that will allow the user to exit the loop at any time
     b)      You should rewrite the loop so that it isn’t an endless loop
     c)       You should use a break statement
     d)      You should use a continue statement

Answer :  C

which of the following is depicted by the code snippet below?

var snowTires=new Array('tire 0','tire 1','tire 2','tire 3','tire 4')
for (var i=0;1<snowTires.length;i++){
if (snowTires[i]){
alert("snowTires" +i+ "is available");
alert("snowTires" +i+ "is not available");

        a)      It is a for looping through an array
        b)      It is just a basic for loop
        c)       It is meant to generate an error message
        d)      It is only an if statement

Answer :  A

The way you access an array is…

a)      …with multiple pieces of data
     b)      ….through a numeric key called an index
     c)       …through a numbering system starting with number 1
     d)      A and C
     e)      All the above

Answer :  B

In viewing thesource code of your company’s”main_include.js”,you see the previous developer has written it to be compact.Based on a snippet of this code below.If “withtax” is passed the value of”14” what is the value returned by “withtax”?

function ad(s){var j;j=fst(s);
return j/100;
function withtax(a)
var j,i;i=a>=10?'PA':'';/*j=ad(i);*/a*=1+ad(i);return Math.round(a);
function fst(m){switch(m)
case 'NJ': return 7.52;
case 'PA' : return 9.99;
case 'DE': return 3.19;
case 'CA': return 8.01;
return 0;
function dnoth(x){var i;for(j=0;j<5;j++)
return –i;

         a)      13
         b)      14
         c)       15
         d)      0

Answer :  

Next Interview Question