Dvojitá otáznik v js

Príklady kódu

12
0

dvojitý otáznik javascript

//Similar to || but only returns the right-hand operand if the left-hand is null or undefined
0 ?? "other" // 0
false ?? "other" // false
null ?? "other" // "other"
undefined ?? "other" // "other"
4
0

dvojitý otáznik javascript

let a = null;
const b = a ?? -1;		// Same as b = ( a != null ? a : -1 );
console.log(b);		  	// output: -1
//OR IF
let a = 9;
const b = a ?? -1;
console.log(b);  		// output: 9

//PS.,VERY CLOSE TO '||' OPERATION IN FUNCTION, BY NOT THE SAME
2
0

Dvojitá otáznik v js

const foo = null ?? 'default string';
console.log(foo);
// expected output: "default string"

const baz = 0 ?? 42;
console.log(baz);
// expected output: 0

Podobné stránky

Podobné stránky s príkladmi

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................