null vs. undefined (javascript)


how well do you know your “null”s and “undefined”s?

write down what you expect the result of each operation to be. run them in a javascript console (ChromeFirefox/FirebugSafari). compare, verify, contrast, and, for fun, give yourself a score out of “3/4 donut”.

// Equality
null == undefined
null === undefined
!null == !undefined
!null === !undefined

// addition and concatenation
null + ''
undefined + ''
null + 1
undefined + 1

// fun with enumerations
test = []; test.push(null); console.log(test)
test = []; test.push(undefined); console.log(test)

[More programming riddles]

recursive touch


i just moved a bunch of media files from one device, to the other, and the file creation dates for a small number of my directories (and their contents) moved a few years into the future.

this problem smelled like a python 1 liner; i came pretty close – highlight to see the code:

import os, sys, subprocess

for d,s,fs in os.walk(sys.argv[1]):
    for p in (s+fs):["touch",os.path.join(d,p)])

(source online, in case I improve it)

[More programming riddles]