PreviousNext…

Friday posers…

Recent projects have meant lots and lots of Javascript. Other work has led to a need to really study the language, and look into more than the odd jQuery plugin and wot-not. This has been a rewarding experience: challenging received wisdom, ensuring that I know more about all those concepts that spend years just floating out there on the edge of one’s understanding.

To that end, here are a few interesting tid-bits which I have found—typically whilst researching more involved stuff like prototypical inheritance and closures :-). It’s amazing how much we think we know…

A couple of the more involved posers have specimen answers attached; the others are too easy for me to do that! It’s all interesting though:

// What do these two alerts produce, and why?
alert('1' + 3);
alert('3' - 1);

// If expressed as tests, what do each of these return?
"1" == 1;
"1" === 1;
"1" == true;
"1" === false;

// What do these calls produce?
parseInt("05");
parseInt("010");
parseInt("09");

// What are the five main data types in Javascript?

// How would you create a class in Javascript, with a private method?
function MyClass()
{
    function somePrivateMethod() {
        console.log("this is a private method");
    }
}

//… how would you add a public method to this class?
MyClass.prototype = {
    somePublicMethod: function() {
        console.log("This is a public function, whoop!");
    }
}

Comments on this post are now closed.

About

I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.

";