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

Variable Hoisting in JavaScript

Will this program alert? Will something be logged to the console?

 alert(5); console.log'alerted';

We are obviously missing some parentheses around the argument passed to console.log but what will that cause the browser to do? This will result in a SyntaxError. Syntax errors do not make it past the interpreter and our program does not run. It is invalid JS and nothing is alerted.

Uncaught SyntaxError: Unexpected string 

What will happen here? Anything alerted or …

Read Article