What is the use of || operator in assignment in JavaScript?

|| operator is used to assign the value if there is no value assigned to it.

Example :-

var vr1 ;

var vr2=vr1 || ‘some value’;


In above example if vr1 is not value then ‘some value' string value will be assigned to vr2.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vishal Pathak

Vishal Pathak


love ❤ coding, solving some industry problems technologies: JavaScript, C#, Angular, PLSQL, Docker Want to learn: Python, Go language, AI, ML and Cloud