the string "2 + 2"
    

For these reasons, the code may break when it encounters ` String ` objects
when it expects a primitive string instead, although generally, authors need
not worry about the distinction.

A ` String ` object can always be converted to its primitive counterpart with
the [ ` valueOf() ` ](/en-
US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf) method.

js

    
    
    console.log(eval(s2.valueOf())); // returns the number 4
    

###  String coercion

Many built-in operations that expect strings first coerce their arguments to
strings (which is largely why ` String ` objects behave similarly to string
primitives). [ The operation ](https://tc39.es/ecma262/multipage/abstract-
operations.html#sec-tostring) can be summarized as follows:

  * Strings are returned as-is. 
  * [ ` undefined ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) turns into ` "undefined" ` . 
  * [ ` null ` ](/en-US/docs/Web/JavaScript/Reference/Operators/null) turns into ` "null" ` . 
  * ` true ` turns into ` "true" ` ; ` false ` turns into ` "false" ` . 
  * Numbers are converted with the same algorithm as [ ` toString(10) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) . 
  * [ BigInts ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) are converted with the same algorithm as [ ` toString(10) ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString) . 
  * [ Symbols ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) throw a [ ` TypeError ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) . 
  * Objects are first [ converted to a primitive ](/en-US/docs/Web/JavaScript/Data_structures#primitive_coercion) by calling its [ ` [@@toPrimitive]() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive) (with ` "string" ` as hint), ` toString() ` , and ` valueOf() ` methods, in that order. The resulting primitive is then converted to a string. 

There are several ways to achieve nearly the same effect in JavaScript.

  * [ Template literal ](/en-US/docs/Web/JavaScript/Reference/Template_literals) : ` `${x}` ` does exactly the string coercion steps explained above for the embedded expression. 
  * The [ ` String() ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/String) function: ` String(x) ` uses the same algorithm to convert ` x ` , except that [ Symbols ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) don't throw a [ ` TypeError ` ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) , but return ` "Symbol(description)" ` , where ` description ` is the [ description ](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/description) of the Symbol. 
  * Using the [ ` + ` operator ](/en-US/docs/Web/JavaScript/Reference/Operators/Addition) : ` "" + x ` coerces its operand to a _primitive_ instead of a _string_ , and, for some objects, has entirely different behaviors from normal string coercion. See its [ reference page ](/en-US/docs/Web/JavaScript/Reference/Operators/Addition) for more details. 

Depending on your use case, you may want to use ` `${x}` ` (to mimic built-in
behavior) or ` String(x) ` (to handle symbol values without throwing an
error), but you should not use ` "" + x ` .

###  UTF-16 characters, Unicode code points, and grapheme clusters

Strings are represented fundamentally as sequences of [ UTF-16 code units
](https://en.wikipedia.org/wiki/UTF-16) . In UTF-16 encoding, every code unit
is exact 16 bits long. This means there are a maximum of 2  16  , or 65536
possible characters representable as single UTF-16 code units. This character
set is called the [ basic multilingual plane (BMP)
](https://en.wikipedia.org/wiki/Plane_\(Unicode\)#Basic_Multilingual_Plane) ,
and includes the most common characters like the Latin, Greek, Cyrillic
alphabets, as well as many East Asian characters. Each code unit can be
written in a string with ` \u ` followed by exa