Reputation: 12224
I want to set a variable to an empty string in Javascript, a pretty routine thing. I just don't know how to do it without doing this:
if (existingnote==null) {
existingnote = "";
}
Is there a faster or easier way?
Upvotes: 2
Views: 973
Reputation: 2665
There is now shorthand for @DaveNewton answer
let existingnote = null
existingnote || = "";
console.log(existingnote)
Upvotes: 0
Reputation: 1706
If you want just null
to work this way, try
existingnote = (existingnote === null? "": existingnote);
Upvotes: 0
Reputation: 160191
existingnote = existingnote || "";
This checks for truthy/falsy, which may not be what you want.
Upvotes: 3