I\'m wondering if there\'s a shorter way to write this:
var x = 1; if(y != undefined) x = y;
I initially tried x = y || 1, but
x = y || 1
You can try if/else this shorthand method:
// Syntax if condition || else condition // Example let oldStr = ""; let newStr = oldStr || "Updated Value"; console.log(newStr); // Updated Value // Example 2 let num1 = 2; let num2 = num1 || 3; console.log(num2); // 2 cause num1 is a truthy