I am Hack Sparrow
Captain of the Internets.

Archive for JavaScript

JSLint from the Command Line

Maybe you have heard about JSLint, or maybe not. If you haven't yet, it is a popular JavaScript tool authored by Douglas Crockford, which helps you optimize your JavaScript code by telling you the problem areas and suggesting solutions for the same. Quite a nifty tool, try it here. Despite it's usefulness, the JSLint as we know it, has a little problem: it is an online tool, hosted on Crockford's server. Wouldn't it be wonderful if JSLint were a command ...

JavaScript Array-like Objects

Have you heard about array-like objects in JavaScript? If no, this is a good post to learn about them. Array-like objects are not a separate object type, they are the same old object we are familiar with, except they 'look' like arrays. What do I mean by that? Let's find out. You might be familiar with the arguments variable which every JavaScript function has access to by default. We access its items using arguments[0], arguments[1] etc. Let's take a lo ...

JavaScript Test – Round One

Applying for a job somewhere as a JavaScript developer? Or just wanna see how much of JavaScript you know? Here is something useful and fun for you. Let's assume I won't consider anyone for the next round, who fails to answer atleast 95% of these questions. Yes, this is the first round :twisted: 1. What are some negative stuff about JavaScript, the language? 2. What can you do to mitigate the effects of those negative stuff? 3. What are the primitive data types in JavaScript? 4. What ar ...

JavaScript – Use Variables with Regular Expressions

So you know the basics of Regular Expressions in JavaScript and often use it for replacing text etc. Example: [code] var sentence = 'Regular Expression'; sentence.replace(/ssion/, 'shun'); // "Regular Expreshun" [/code] Now what if the string you need to replace needs to be flexible? Well you could use a variable! [code] var replacee = 'sion'; var replacer = 'hun'; sentence.replace(/+ replacee +/, replacer); // SyntaxError ...

JavaScript – Check Object Property is Defined

Probably you know how to check if a variable is defined in JavaScript or not (without crashing your app with a fatal ReferenceError). In case you didn't know already, here is a refresher. Wrong: [code] if (username == undefined) { console.log('username missing'); } else { console.log(username); } [/code] Right: [code] if (typeof username === 'undefined') { console.log('username missing'); ...