VOOZH about

URL: https://www.geeksforgeeks.org/javascript/are-string-objects-in-javascript/

⇱ Are String Objects in JavaScript? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Are String Objects in JavaScript?

Last Updated : 23 Jul, 2025

Strings in JavaScript are one of the primitive data types, alongside numbers, booleans, null, undefined, bigint, and symbols. Unlike objects, primitives do not have methods or properties of their own. However, when you attempt to call a method or access a property on a string, JavaScript automatically wraps the string in a String object to provide access to methods.


Output
string
5
42
true

The String Object

JavaScript has a built-in String object that can be explicitly used to create string objects. This is different from primitive strings.


Output
object

Key Differences Between Primitives and String Objects

FeaturePrimitive StringString Object
Type"string""object"
Memory EfficiencyMore efficientLess efficient
Use CaseHighly used in creating stringRarely used

Tip: Always prefer primitive strings for simplicity and performance.

Why the Confusion?

The confusion arises because strings appear to have methods and properties like objects, but they are primitives. The temporary wrapping of primitives into String objects is what enables this behavior.


Output
true

Here, JavaScript implicitly wraps the string in a String object to access the .constructor property.

Comment