Ask HN: What would you change about JavaScript if you could?
Ideally replies with a minimum of snark.
"Change the syntax to Python <or your favorite language>" isn't the sort of reply that would be helpful in this thread.
"Change the syntax to Python <or your favorite language>" isn't the sort of reply that would be helpful in this thread.
I also wish JavaScript were generally better at functional programming - I'd love to see a keyword that ensures that no form of mutation is possible within a given scope.
Function level scope would be great too - it would be good to conditionally declare and set variables in a function without needing to pre-declare the variable outside the condition test.
if foo === 'FOO' && bar > 7 {
console.log(bar)
return true
}else if typeof foo === 'string'{ return false
}return null
textarea.onkeydown = event => {
// doesn't get the properties until they're accessed
const get {selectionStart, selectionEnd, value} = textarea;
// doesn't actually call .slice yet
const get selectedText = value.slice(selectionStart, selectionEnd);
// ...
if (event.key === "Enter") {
// initializes selectedText
console.log("selected text: " + selectedText);
// uses the same value, doesn't reinitialize it
selectedText;
}
};