# 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.

Bron: [JavaScript Data Types: When does 2 +2 = 22? | by Stephanie De Smedt](https://medium.com/@simply_stef/understanding-javascript-data-types-when-does-2-2-22-6ca3629690ab#:~:text=If%202%20is%20entered%20as,data%20type%20is%20a%20string.)

Onderwerp: [Techniek & internet](https://1001vragen.nl/onderwerp/techniek-en-internet)
Toegevoegd: 2026-01-26
Webpagina: https://1001vragen.nl/vraag/what-is-the-output-of-2-2-in-javascript

## 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" .

Bron: [What will be the output of console. log (2+ ''2''); in JavaScript?](https://www.gauthmath.com/solution/1986028325791620/What-will-be-the-output-of-console-log-2-2-in-JavaScript-#:~:text=The%20concatenation%20of%20%222%22%20and,in%20the%20string%20%2222%22%20.&text=log()%20function-,The%20console.,is%20the%20string%20%2222%22%20.)

## 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.

Bron: [Addition assignment (+=) - JavaScript - MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition_assignment#:~:text=The%20addition%20assignment%20(%20%2B%3D%20)%20operator,result%20to%20the%20left%20operand.)

## 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.

Bron: [What is the difference between "+=" and "=+"? - Sololearn](https://www.sololearn.com/en/Discuss/2146936/what-is-the-difference-between-and-#:~:text=There's%20a%20conceptional%20difference%20between,way%20creates%20a%20separate%20object.)

## 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() .

Bron: [JavaScript Output](https://www.w3schools.com/js/js_output.asp)

## Verwante vragen

- [What is the purpose of using dbms_output put_line in a pl SQL block?](https://1001vragen.nl/vraag/what-is-the-purpose-of-using-dbms-output-put-line-in-a-pl-sql-block.md)
- [What is the use of dbms_output put_line?](https://1001vragen.nl/vraag/what-is-the-use-of-dbms-output-put-line.md)
- [What is TypeScript vs JavaScript?](https://1001vragen.nl/vraag/what-is-typescript-vs-javascript.md)
- [Can I use JavaScript in TypeScript?](https://1001vragen.nl/vraag/can-i-use-javascript-in-typescript.md)
- [What does the '%' wildcard symbol represent in SQL?](https://1001vragen.nl/vraag/what-does-the-wildcard-symbol-represent-in-sql.md)
- [How to concatenate a SELECT statement?](https://1001vragen.nl/vraag/how-to-concatenate-a-select-statement.md)
- [What is the default value of Group_concat_max_len?](https://1001vragen.nl/vraag/what-is-the-default-value-of-group-concat-max-len.md)
- [What is the separator of Group_concat in MySQL?](https://1001vragen.nl/vraag/what-is-the-separator-of-group-concat-in-mysql.md)
- [What is the maximum length of Group_concat in MySQL?](https://1001vragen.nl/vraag/what-is-the-maximum-length-of-group-concat-in-mysql.md)
- [Which SQL command is used to retrieve all the columns from a table named employees?](https://1001vragen.nl/vraag/which-sql-command-is-used-to-retrieve-all-the-columns-from-a-table-named-employees.md)
