JavaScript Basics (Character-Number Calculation)

Asked 2 years ago, Updated 2 years ago, 19 views

<script>
alert("abc"+1+2)
alert(1+2+"abc")
</script>

The first line is to add a number from the letter + number (when viewed as a whole) It's abc12.

The second line is a number plus a number plus a letter Is it 3abc?

Can I understand that the value varies depending on the location of the character?

It's simple. I'm confused.

javascript

2022-09-22 20:06

1 Answers

This is due to the priority of the operator.

If only added, the left side is calculated first, so it depends on whether the left side comes first with a string + string (or another type of value that can be converted into a string) or a number + number.


2022-09-22 20:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.