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’;

Explanation:-

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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Best Practices in Angular Application Development

Angular API File Download

Frame courtesy — চালচিত্র / The Kaleidoscope (1981)

TypeScript Solutions: Converting Object Props With Undefined Type to Optional Props

Taking React Animation to next level

Create an Application-Wide Menu in Angular Using Material UI

Plans for Memo App

How to D3 in React 16.3 and beyond

Building Eviction Free NYC with GatsbyJS + Contentful

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

More from Medium

How to fix blurry elements that have “position: fixed”

A speeding train blurred by its motion

How to Import JSON file as a Module

7 Must-know attributes of <script> for every front-end developer

What is Reactive JavaScript?