JavaScript String prototype Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Static property

Definition

String.prototype is the shared object that holds String instance methods such as slice(), trim(), and includes(). Primitive strings temporarily use this prototype when you call a method.

This is different from the String() constructor page, which teaches creating and converting strings.

Syntax

Read the prototype on the String constructor itself.

JavaScript
console.log(typeof String.prototype);
console.log(typeof String.prototype.slice);
console.log("hi".slice === String.prototype.slice);
CallWhat it does
String.prototypePrimary form.

Static property on String. Instance methods live here.

Parameters

ParameterDescription
String.prototypeObject shared by string instances. Not called like a function.

Return Value

Return ValueDescription
ObjectThe prototype object containing String instance methods.

JavaScript Examples

Example 1 — Methods Live on the Prototype

Confirm common methods exist on String.prototype.

JavaScript
console.log(typeof String.prototype.trim);
console.log(typeof String.prototype.includes);
console.log("Hi".toUpperCase === String.prototype.toUpperCase);
Try It Yourself

How It Works

  1. Functions on the prototype. trim and includes are functions.
  2. Shared reference. Instance methods point at the same function on the prototype.

Example 2 — Call Through a String

Primitives borrow prototype methods.

JavaScript
const text = "  CodeToFun  ";
console.log(text.trim());
console.log(String.prototype.trim.call(text));
Try It Yourself

How It Works

  1. Normal call. text.trim() looks up trim on String.prototype.
  2. Explicit call. String.prototype.trim.call(text) does the same work.

Example 3 — prototype vs length

Static prototype vs instance length.

JavaScript
console.log("hi".length);
console.log(Object.getPrototypeOf("hi") === String.prototype);
console.log(String.prototype.length);
Try It Yourself

How It Works

  1. Instance length counts characters on that string.
  2. Prototype link for a string primitive boxes to String.prototype.
  3. String.prototype.length is 0 because the prototype object is an empty String exotic object.

Browser & Runtime Support

String.prototype is a core language feature from the earliest editions of JavaScript.

✓ Baseline · ES1+

String.prototype

Supported everywhere String exists.

99% Universal
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
String.prototype Excellent

Bottom line: Safe everywhere.

Frequently Asked Questions

The object that stores shared String instance methods like slice() and trim().
No. The constructor tutorial is /js/string/constructor. This page is the prototype property.
JavaScript temporarily wraps the primitive, finds trim on String.prototype, and calls it.
Usually no in application code — it affects every string and can clash with libraries.
Browse the String Methods index for slice, trim, includes, and the rest.

Explore String methods

slice, trim, includes, and more live on the prototype.

Methods index →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful