What is the output of 2 +' 2 in JavaScript?

If 2 is entered as a number the answer is as we might expect, 2+ 2 = 4 and the resulting data type is a number. However, if one (or both) of the 2s are handled as a string the result is very different. In that case, 2 + “2” becomes 22 and the resulting data type is a string. Lees verder »

Bron: medium.com

What will be the output of console log 2+ 2?

The concatenation of "2" and "2" results in the string "22" . The console. log() function in JavaScript will output the value of its argument to the console. In this case, the argument is the string "22" . Lees verder »

What is += in JavaScript?

The addition assignment ( += ) operator performs addition (which is either numeric addition or string concatenation) on the two operands and assigns the result to the left operand. Lees verder »

Is =+ or +=?

There's a conceptional difference between x+=y and x = x+y. The idea is that += changes 'this very object', while the other way creates a separate object. Lees verder »

How to write output in JavaScript?

  • Writing into an HTML element, using innerHTML or innerText .
  • Writing into the HTML output using document.write() .
  • Writing into an alert box, using window.alert() .
  • Writing into the browser console, using console.log() .
  • Lees verder »
Gerelateerd aan What is the output of 2 +' 2 in JavaScript?