Javascript-Related-query

console.log(null || “name”);
Could you please explain this with output.
@kashif-ta-fsr

1 Like

@nagman2727 ,
Output is “name”, because the `null value represents the intentional absence of any object value. Here it is mentioned null or (||) name, then obviously it will consider name only, if in the case of console.log(null), it will show output as null only since there is no alternate value for this.

1 Like

Okay. If it is like console.log(“riya” || “jiya”); then?

1 Like

@nagman2727
The output of the code console.log("riya" || "jiya"); will be “riya”.

In JavaScript, the || operator returns the first truthy value it encounters when evaluating expressions from left to right.

In this case, both "riya" and "jiya" are truthy values, but "riya" is the first expression evaluated from left to right, and it is already a truthy value. Therefore, the || operator will return "riya", and it will be printed to the console by console.log().

2 Likes

@dharshini-ta-fsr Okay .I got it. Thank you…

1 Like