Posts

Showing posts from April, 2013

Win a ticket for Fluent Conference

Update 2013-05-03: A winner has been determined and received the ticket. Fluent Conference takes place in San Francisco from May 28–30, 2013. Its tag line is “JavaScript & Beyond”. The 2ality blog raffles off a ticket for the last two days (excluding the workshop day). To win, tweet the following text: I’d like to win a ticket for Fluent Conference. #2alityFluent http://www.2ality.com/2013/04/fluent-raffle.html The deadline is Friday, May 3rd, 2013, 14:00 GMT. I’ll contact the winner via Twitter, within a few hours of the deadline. (If the winner isn’t following me already, I’ll ask them to temporarily do so, so that I can send them a direct message.) [Legal disclaimer: I make no guarantees w.r.t. to there being a winner. Contesting this raffle via legal means is not allowed.]

More Than She'll Ever Know

Image
It was late summer, and I had stopped in at my parents’ house on my way home from my dead end, department store security job when my mother suggested I apply to be a teacher.   This was a remarkable suggestion for a number of reasons. One, my bachelor’s degree was not finished after almost five years.   I still had one, three-unit class to complete.   I was already registered for the class that fall on Tuesdays and Thursdays at 4:20 in the afternoon.   Surely this would interfere with any teaching position. Two, my mother was never one to encourage.   She was so much better at discouraging, or bringing out in excruciating detail all the ways I would fail in any given situation. Third, we did not get along.   This rift was especially bad that August because against my parents’ wishes, I had gotten married.   Worse, my ceremony was not in the Catholic Church.   My mother did not like my wife just because she was my wife.   She hadn’t liked her any better when she was my girlfriend.   I

JavaScript quirk 4: unknown variable names create global variables

[This post is part of a series on JavaScript quirks.] Normally, JavaScript automatically creates a global variable if you use an unknown variable name: > function f() { foo = 123 } > f() > foo 123 Thankfully, you get a warning in ECMAScript 5 strict mode [1] : > function f() { 'use strict'; foo = 123 } > f() ReferenceError: foo is not defined Reference: JavaScript’s strict mode: a summary

Trust Wisdom and Experience

Image
I have been watching a lot of NBA basketball lately, mainly to try to relax at the end of a hectic day.   I’m following my two hometown teams:   the Lakers for the drama; and the Clippers for their high flying, high energy entertainment.   The Lakers, according to those in the know (and anyone else with eyes and half a brain), will not go far in the playoffs with an aging team and an injured force of nature that was Kobe Bryant before tearing up his Achilles tendon.   The Clippers are a younger, more athletic team, and I root for them because they get no respect and are considered the underdog to win the conference, much less the championship after so many years of irrelevancy. American culture has an age bias, and the Lakers are an example of what happens in the real world.   Sports writers and fans bemoan the team’s creaky old-timers and their lack of athleticism.   Never mind that combined, the team’s veterans bring thousands of games played to the table.   These are crafty athlete

JavaScript quirk 3: normal equality (==)

[This post is part of a series on JavaScript quirks.] Let’s start with a simple rule: the normal equality operators == and != are so problematic that you should always use strict equality ( === and !== ). Some people say that there are exceptions to this rule, I disagree [2] . Keeping this rule in mind, we can now take a look at what is strange about == without burdening our minds unnecessarily. The “normal” equality operator ( == ) has many quirks. While it is forgiving, it does not adhere to the typical rules of truthy and falsy (see quirk 1 ): > 0 == false // OK true > 1 == true // OK true > 2 == true // not OK false > '' == false // OK true > '1' == true // OK true > '2' == true // not OK false Apart from that, it lets you compare values that aren’t really comparable: > '' == 0 true > '\n 123 \t' == 123 true The last check is true because conv

Checking for undefined: === versus typeof versus falsiness

There are several ways of checking whether a variable has the value undefined . This blog post explains the differences. Checking via === Using strict equality [1] is the canonical way of checking for undefined : if (x === undefined) ... Changing undefined undefined is a property of the global object (and thus a global variable). Under ECMAScript 3, you could change its value. Under ECMAScript 5, you can’t do that, any more: > undefined = 123 > undefined undefined You can, however, shadow it in a function, either via a parameter or via a local variable: > (function () { var undefined = 123; return undefined; }()) 123 From now on, undefined is used to refer to the identifier, while undefined is used to refer to the actual value. Because you could globally change the value of undefined under ECMAScript 3, two techniques were often used to ensure that it had the correct value. If you are targeting older browsers, these techniques are still relevant.

News is bad for you

Quoting “ News is bad for you – and giving up reading it will make you happier ” (by Rolf Dobelli for The Guardian): In the past few decades, the fortunate among us have recognised the hazards of living with an overabundance of food (obesity, diabetes) and have started to change our diets. But most of us do not yet understand that news is to the mind what sugar is to the body. News is easy to digest. The media feeds us small bites of trivial matter, tidbits that don't really concern our lives and don't require thinking. This has been on my mind for a long time: Most of the stuff you learn via the news is just as relevant for your actual life as, for example, the politics of Westeros . It’s too far away to matter, a single incident (that we can’t help but generalize), too limited a perspective (a single person writing about a general issue), etc. The uselessness of that knowledge can be easily demonstrated by looking at a newspaper from a year ago: how much of its content is sti

JavaScript quirk 2: two “non-values” – undefined and null

[This post is part of a series on JavaScript quirks.] Most programming languages have only one value for “no value” or “empty reference”. For example, that value is null in Java. JavaScript has two of those special values: undefined and null . They are basically the same (something that will change with ECMAScript 6, as will be explained in the last post of this series), but they are used slightly differently. undefined is assigned via the language itself. Variables that have not been initialized yet have this value: > var foo; > foo undefined Similarly, JavaScript assigns undefined to missing parameters: > function id(x) { return x } > id() undefined null is used by programmers to explicitly indicate that a value is missing. E.g. for JSON.stringify() : > console.log(JSON.stringify({ first: 'Jane' }, null, 4)) { "first": "Jane" } Check: does a variable have a value? If you want to know whether

Something Rather Than Nothing

Image
The first thought I had upon starting to read Jim Holt’s book, Why Does The World Exist?  An Existential Detective Story (Liveright, 2012), was that my working class father and other men of his generation worked and lived through their days without this question ever crossing their minds.   It was irrelevant because you did exist, and it was sink or swim.   There was no time for thinking about how you came to be in the water paddling for your life.   You were born, you went to school, you found a nice girl, married and settled down, had children, and in my father’s case, you worked ten hour shifts at the brewery seven days a week to keep bread on the table for your growing family.   Then, you retired at 65, and in retirement, depending on what had happened in your life, you might wonder what it all meant.   So Holt’s questioning might be seen as a tad bit precious, but it’s not. Outside of the academy, it is rare for any human being to put as much contemplative thought into this que