javascript - Need solution for if statement logic -


i need on condition logic using if statement following:

  • variables , b contain 3 properties level1, level2 , level3.
  • level1 , level2 can 0 or more , level3 null or numeric.
  • variables , b can null.

currently have condition:

if (a.level1 == 0 , b.level1 == 0) {   code here } else if (a.level2 == 0 , b.level2 == 0) {   code here } else if (a.level3 != null , b.level3 != null) {   code here } 

the problem code doesn't handle variables , b can null part. code should handle part this:

  • when null, b still go through same condition without , vice versa.
  • however, if , b null condition false @ once.

i have problem in how implement variables , b can null part in condition, advice?

add a , b isnull check in condition:

if (a == null && b == null) {     return; } else if ((a == null || a.level1 == 0) && (b == null || b.level1 == 0)) {     // code here } else if ((a == null || a.level2 == 0) && (b == null || b.level2 == 0)) {     // code here } else if ((a == null || a.level3 != null) && (b == null || b.level3 != null)) {     // code here } 

explanation,

take example in else if ((a == null || a.level1 == 0) && (b == null || b.level1 == 0)) statement:

by putting a == null || in (a == null || a.level1 == 0) && (b == null || b.level1 == 0), if null, a.level1 == 0 check ignored, check equivalent else if (b == null || b.level1 == 0).

since first if check a == null && b == null, else if below won't have , b both null. therefore else if ((a == null || a.level1 == 0) && (b == null || b.level1 == 0)) equivalent else if (b.level1 == 0).

p.s. here taking advantage of || characteristic, if first condition fulfilled, second condition ignored.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -