JavaScript pattern matching