Value vs Reference Assignment in JavaScript

In my opinion, value vs reference assignment is an important topic that many JS beginners don’t stop and think about enough.

Let’s test your knowledge of this concept with some puzzles.

Puzzle #1:

This first puzzle is part of Douglas Crockford’s function challenges. You can watch some of his exercises in the free video sample at FrontEndMasters.

What is x?

function funky(o) { o = null; } var x = []; funky(x); alert(x);

o is a parameter …

Read Article

Understanding RegEx in JavaScript

When I first started learning RegEx, I thought it was the most cryptic thing ever and it seemed impossible to learn.  I think we’ve all heard the quote by Jamie Zawinski, “Some people, when confronted with a problem, think ‘I know, I’ll use regular expressions.’ Now they have two problems.”  I mean, what could (\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6}) possibly mean?

Since then, I’ve learned to love them. Turns out, the above RegEx is pretty common and easy to …

Read Article

this in JavaScript

All you ever need to know about this is that this is the current context.

Ryan Morr has a good explanation of the difference between scope and context.

Every function invocation has both a scope and a context associated with it. Fundamentally, scope is function-based while context is object-based. In other words, scope pertains to the variable access of a function when it is invoked and is unique to each invocation. Context is always the …

Read Article

Prototypal Inheritance in JavaScript

Every function has a prototype property that is an object originally set with at least two properties:

constructor: points back to the function itself __proto__: points to the prototype that the function’s prototype itself (an object) inherited from. (Object.prototype)

If that description of the __proto__ property doesn’t make much sense, I’m hoping it will by the end of this article.

Every object has a __proto__ property. When a new instance of an object is created, the __proto__ property points …

Read Article