Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nullish coalescing js


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
Comment

nullish coalescing operator in javascript

//nullish coalescing operator in js
Expression:
	Left ?? Right
if left is null or undefined , then Right will be the value

let value = null ?? "Oops.. null or undefined";
console.log(value) //Oops.. null or undefined

value = undefined ?? "Oops.. null or undefined";
console.log(value) //Oops.. null or undefined

value = 25 ?? "Oops.. null or undefined";
console.log(value) // 25

value = "" ?? "Oops.. null or undefined";
console.log(value) // ""
Comment

js nullish coalescing ?? vs logical or ||

The OR operator || uses the right value if left is falsy 
(e.g. "" or 0 or false), while the nullish coalescing operator ?? uses
the right value if left is null or undefined.
Comment

PREVIOUS NEXT
Code Example
Javascript :: document.on chenage jquer 
Javascript :: remove duplicated from array of ojects 
Javascript :: modal show with jquery ready function 
Javascript :: for each javascript 
Javascript :: virtual dom explained 
Javascript :: display content in a modal react 
Javascript :: download file from api vue 
Javascript :: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html" 
Javascript :: javascript get 1 hour from now 
Javascript :: post xml with axios nodejs 
Javascript :: queryselector get each element 
Javascript :: array to object 
Javascript :: write json file c# 
Javascript :: javascript password hashing 
Javascript :: js pad 2 
Javascript :: Accessing $route.params in VueJS 
Javascript :: java script remove last character from string 
Javascript :: shuffle array item javascruitp 
Javascript :: refresh page by hand in react 
Javascript :: how to get on click id in event 
Javascript :: javascript bigint 
Javascript :: add regexp to antd 
Javascript :: moment js get date 1 month 
Javascript :: set timeout for loop 
Javascript :: if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1. 
Javascript :: how to change background color though props 
Javascript :: Use Destructuring Assignment with the Rest Operator to Reassign Array Elements 
Javascript :: angularjs date filter 
Javascript :: object clone javascript 
Javascript :: export all javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =