Get the App
SLTechnology News&Howtos  ›  Development  › 

How to abbreviate variable assignment in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:38:45 09月22日 Update

This article is about how to abbreviate variable assignment in JavaScript. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Variable assignment

When assigning the value of one variable to another, you first need to make sure that the original value is not null, undefined, or null.

This can be achieved by writing a judgment statement that contains multiple conditions:

If (variable1! = = null | | variable1! = = undefined | | variable1! ='') {let variable2 = variable1;}

Or abbreviated to the following form:

Const variable2 = variable1 | | 'new'

You can paste the following code into es6console and test it yourself:

Let variable1;let variable2 = variable1 | |'; console.log (variable2 = =''); / / prints truevariable1 = 'foo';variable2 = variable1 | |'; console.log (variable2); / / prints foo Thank you for reading! This is the end of this article on "how to abbreviate variable assignment in JavaScript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Variables abbreviations content more articles good practical code original values can be passed multiple forms articles conditions see knowledge sentences face reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi Shulou Technology Microsoft MariaDB