How JavaScript uses union conditionals
This article is about how to use JavaScript and conditional characters. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Union condition character
If you have a piece of code like this:
If (conected) {login ();}
You can also abbreviate variables and connect them with functions using & &, such as the example above, which can be simplified like this:
Conected & & login ()
If some properties or functions exist in an object, you can also do this detection, as shown in the following code:
User & & user.login ()
Use the | | operator
There is a default parameter feature in ES6. To simulate this feature in older browsers, you can use the | operator and pass in the default value as the second parameter. If the value returned by the * * parameter is false, the second value will be considered as a default value. Such as the following example:
Function User (name, age) {this.name = name | | "Oliver Queen"; this.age = age | | 27;} var user1 = new User (); console.log (user1.name); / / Oliver Queen console.log (user1.age); / / 27 var user2 = new User ("Barry Allen", 25); console.log (user2.name); / / Barry Allen console.log (user2.age); / / 25 Thank you for reading! This is the end of this article on "how to use JavaScript and conditional characters". 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!