I'm curious to know that what does a ?? mean in JS?
form.inputs.forEach(input => {
stepProperties[input.field] = {
info: input.fieldInfo,
description: input.fieldLabel,
default: input.fieldDefault ?? '',
...getInputType(input.fieldType, fieldTypes),
};
itemToPush.properties = stepProperties;
});
in the above code snippet the value of default key is input.fieldDefault ?? ''
would like to understand this line.
I did google but did not get any proper answer.
It's the nullish coalescing operator, if the left side is null or undefined it will return the right side
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.
let input = {};
let variable = input.fieldDefault;
console.log(`variable is undefined : ${variable == undefined}`);
variable = input.fieldDefault ?? '';
console.log(`variable is undefined : ${variable == undefined}`);
console.log(`variable is empty string : ${variable == ''}`);