What is the output of the expression 5 + '5' in JavaScript?

Prepare for the Revature Test with our comprehensive study material. Use flashcards and multiple-choice questions, each with hints and explanations. Get exam-ready now!

In JavaScript, the expression 5 + '5' demonstrates the concept of type coercion, where the JavaScript engine converts values to a common type to perform operations. In this case, one operand is a number (5) and the other is a string ('5').

When the addition operator (+) is used, JavaScript first checks the types of both operands. Since one of the operands is a string, JavaScript converts the number to a string to perform string concatenation. As a result, the number 5 is converted to the string '5', and then these two strings are concatenated together.

Thus, the final output of the expression is "55", which is the string result of combining the two string representations. This highlights how JavaScript handles operations involving different data types and illustrates the flexibility of the language in managing type coercion during operations.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy