Day 8 of the Guess the Output Series: Tricky Javascript Question (Set #shorts)! #javascript #nodejs #yt

Posted by

Javascript | Guess the Output Series | Tricky Question | Day 8

#shorts #javascript #nodejs #yt

Today, we are going to explore a tricky Javascript question in our Guess the Output Series. Let’s see if you can guess the correct output!

let x = 5;
let y = 10;

console.log(x + y + “5”);
console.log(“5” + x + y);
console.log(“5” + (x + y));

In this code snippet, we have three console.log statements with different combinations of strings and numbers being concatenated.

The first console.log statement:
x + y is calculated first, resulting in 15. Then, “5” is concatenated to the result, which gives us “155”.

The second console.log statement:
Since the first operand is a string “5”, the following operands are concatenated as strings instead of adding them as numbers. Therefore, the result of this statement is “510”.

The third console.log statement:
In this case, the parentheses enforce the addition of x and y first, resulting in 15. Then, “5” is concatenated to the result, giving us “155”.

I hope you were able to guess the correct outputs! Thank you for participating in our Guess the Output Series. Stay tuned for more tricky Javascript questions in the future! #shorts #javascript #nodejs #yt

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@devnodeX
7 months ago

Like Share Subscribe for more videos❤️