Sometimes you will see English commas "," in the if statement in JavaScript. This is actually a comma expression. In the if condition, only the last expression plays a role. Consider the following example: let a = 1, b = 2, c = 3; // if only checks the last expression if (a == 10, b == 20, c == 3) { console.log("c == 3"); } else { console.log("c != 3") } // Console output: // c == 3 There are 3 expressions in the above Although if only checks the last expression, the previous expressions will also be executed. Please refer to the following code: let a = 10, b = 20, c = 30; // if only checks the last expression, but the previous expressions will also be executed if (a = 1, b = 2, c == 3) { console.log("c == 3"); } else { console.log("c != 3") } // Console output: // c != 3 console.log(a, b); // Console output: // 1 2 In the But the first two expressions are executed, so finally This is the end of this article about if contains comma expression in JavaScript. For more related content about if contains comma expression in JavaScript, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Implementing long shadow of text in less in CSS3
>>: Div can input content without using input as an input box to block the automatic input style
Table of contents Preface: Detailed introduction:...
The complete steps of Centos7 bridge network conf...
This article shares the specific code of JavaScri...
1. Use docker images to view all the image files ...
First, understand the updatexml() function UPDATE...
This article example shares the specific code of ...
This article shares the specific code of JavaScri...
As a front-end developer, I can’t avoid IE’s pitf...
Preface This article will share some docker-compo...
Table of contents DOMContentLoaded and load What ...
Table of contents 1. What is a regular expression...
Sometimes some docker containers exit after a per...
Written in front A database is essentially a shar...
Install the required environment 1. gcc installat...
Table of contents Purpose Experimental environmen...