Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

double question mark javascript

Nullish coalescing operator (??)
returns its right-hand side operand when its left-hand side operand is null or undefined, 
and otherwise returns its left-hand side operand.
const foo = null ?? 'default string';
console.log(foo);
// expected output: "default string" because left hand side is null.

const baz = 0 ?? 42;
console.log(baz);
// expected output: 0 , because left hand side ( 0 )  is not null or undefinded.
Comment

double question mark 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"
Comment

javascript double question mark

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
Comment

double question mark javascript

b = a ?? -1
_____________
if(a != null){
	b = a;
}
else{
	b = -1;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: naming branches git 
Javascript :: javascript to help find overflow elements 
Javascript :: style before javascript 
Javascript :: How to add and play sounds in JS 
Javascript :: string contains in javascript 
Javascript :: java scipt 
Javascript :: reset form javascript/jquery 
Javascript :: how to add a shadow react native 
Javascript :: lodash deep clone object 
Javascript :: javascript select all elements 
Javascript :: react js empty build 
Javascript :: url decode in javascript 
Javascript :: how to make slide js in owl carousel auto 
Javascript :: Javascript console log a int 
Javascript :: how to detect clicks with javascript 
Javascript :: javascript setattribute 
Javascript :: javascript infinite loop 
Javascript :: sleep js 
Javascript :: object element by index javascript 
Javascript :: react open url with button 
Javascript :: javascript execute string code 
Javascript :: check if array has same values javascript 
Javascript :: javascript iterate over chars in string 
Javascript :: EVERY METHOD 
Javascript :: js cookies 
Javascript :: scrollheight jquery 
Javascript :: ReferenceError 
Javascript :: how to use compare password in node js 
Javascript :: javascript check if dom element exists 
Javascript :: get cookie javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =