How to abbreviate variable assignment in JavaScript
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!