3 ms·
What a mess. switch x 0 console.log("zero") /^\s+$/ console.log("whitespace") [{type: "text", content}, ...rest]
by rty32 2y ago
What a mess.
switch x
0
console.log("zero")
/^\s+$/
console.log("whitespace")
[{type: "text", content}, ...rest]
console.log("leading text", content)
Yes, looks very cool, but nobody should ever write code like this, especially not in strictly typed code. And it is extremely rare you need to do similar pattern matching. For the object case, you would want to define interfaces and type guards in TypeScript anyway. This feels like poor man's pattern matching compared to Python and Rust.
items = for item of items
if item.length
item.toUpperCase()
else
"<empty>"
If JavaScript has always required statements to end in semicolon, I'm 100% for this. But it's not. So "standalone expression" as return value will only cause chaos.