You are browsing the archive for tricky.

JavaScript Quiz #12

December 17, 2013 in JavaScript

Assume that we have the following short JavaScript code:

<script>
    var number = 50;
    var obj = {
        number: 60,
        getNum: function () {
	    var number = 70;
	    return this.number;
	}
    }; 

    alert(obj.getNum());
    alert(obj.getNum.call());
    alert(obj.getNum.call({number:20}));
</script> 

Will this code succeed or fail? and if it succeeds, what is the output of the alerts?

Read the complete answer

JavaScript Quiz #11

November 2, 2013 in JavaScript

Assume that we have the following short JavaScript code:

<script>
    var x = !!"Hello" + (!"world", !!"from here!!");
    
    alert(x);
</script> 

Will this code succeed or fail? and if it succeeds, what is the output of the alert?

Read the complete answer

JavaScript Quiz #10

November 2, 2013 in JavaScript

Assume that we have the following short JavaScript code:

<script>
    var y = 10;

    if (!(x in window)) {
        var x = 10;
    } else {
        ++y;
    }

    alert(x);
    alert(y);
</script>

Will this code succeed or fail? and if it succeeds, what is the output of the alerts?

Read the complete answer

JavaScript Quiz #8 (One line Quiz)

May 9, 2013 in JavaScript

Assume that we have the following short JavaScript code:

<script>
    var result = (2..valueOf() + ({z : 10, x : 20}).x);
    alert(result);
</script>

What is the output of each alert?

Know the complete answer

JavaScript Quiz #7

April 30, 2013 in JavaScript

Assume that we have the following short JavaScript code:

<script>
    var result = typeof("Hello" instanceof String);
    alert(result); //What is the output of the alert? 
	
    result = typeof typeof("Hello" instanceof String);
    alert(result); //What is the output of the alert? 
	
    result = typeof typeof typeof("Hello" instanceof String);
    alert(result); //What is the output of the alert? 	
</script>

What is the output of each alert?

Know the complete answer

Skip to toolbar