惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
D
Docker
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
月光博客
月光博客
小众软件
小众软件
量子位
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
罗磊的独立博客
博客园 - 叶小钗
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
博客园 - 聂微东
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
C
Check Point Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
JavaScript String Methods
Annapoorani Kadhiravan · 2026-06-26 · via DEV Community
Cover image for JavaScript String Methods

Annapoorani Kadhiravan

A String in JavaScript is a sequence of characters used to store text.

let course = "JavaScript";


1. String length

Purpose

Returns the total number of characters in a string.

Syntax

string.length

Example

let company = "OpenAI";

console.log(company.length);

Output

6

Real-Time Example

Checking password length before registration.


2. String charAt()

Purpose

Returns the character at a specified index.

Syntax

string.charAt(index)

Example

let city = "Madurai";

console.log(city.charAt(3));

Output

u

Internal Logic

M a d u r a i
0 1 2 3 4 5 6

Index 3 contains "u".


3. String charCodeAt()

Purpose

Returns the Unicode value (UTF-16 code) of a character.

Example

let letter = "A";

console.log(letter.charCodeAt(0));

Output

65

More Examples

console.log("a".charCodeAt(0));

Output:

97


4. String codePointAt()

Purpose

Returns the Unicode code point of a character.

Useful for emojis and special symbols.

Example

let emoji = "😊";

console.log(emoji.codePointAt(0));

Output

128522

Difference

console.log("😊".charCodeAt(0));
console.log("😊".codePointAt(0));

codePointAt() gives the actual Unicode value.


5. String concat()

Purpose

Combines two or more strings.

Example

let firstName = "Annapoorani";
let lastName = " Kadhiravan";

let fullName = firstName.concat(lastName);

console.log(fullName);

Output

Annapoorani Kadhiravan

Alternative

console.log(firstName + lastName);


6. String at()

Purpose

Returns character at a specific position.

Supports negative indexing.

Example

let language = "JavaScript";

console.log(language.at(0));
console.log(language.at(-1));

Output

J
t


7. String [ ]

Purpose

Access characters using bracket notation.

Example

let laptop = "Dell";

console.log(laptop[0]);
console.log(laptop[2]);

Output

D
l

Difference

console.log(laptop.charAt(0));
console.log(laptop[0]);

Both return same result.


8. String slice()

Purpose

Extracts part of a string.

Syntax

string.slice(start,end)

Example

let course = "JavaScript";

console.log(course.slice(0,4));

Output

Java

Negative Index

console.log(course.slice(-6));

Output

Script


9. String substring()

Purpose

Extracts characters between indexes.

Example

let company = "Microsoft";

console.log(company.substring(0,5));

Output

Micro

Difference from slice()

let str = "JavaScript";

console.log(str.slice(-6));
console.log(str.substring(-6));

Output:

Script
JavaScript

substring() doesn't support negative indexes.


10. String substr()

⚠️ Deprecated (Avoid in new projects)

Purpose

Extracts characters based on start position and length.

Example

let city = "Chennai";

console.log(city.substr(2,4));

Output

enna

Explanation

Start at index 2
Take 4 characters


11. String toUpperCase()

Purpose

Converts string to uppercase.

Example

let name = "annapoorani";

console.log(name.toUpperCase());

Output

ANNAPOORANI


12. String toLowerCase()

Purpose

Converts string to lowercase.

Example

let company = "OPENAI";

console.log(company.toLowerCase());

Output

openai


13. String isWellFormed()

Purpose

Checks whether a string contains valid Unicode characters.

Example

let text = "Hello";

console.log(text.isWellFormed());

Output

true

Use Case

Unicode validation before processing text.


14. String toWellFormed()

Purpose

Converts malformed Unicode into valid Unicode.

Example

let text = "\uD800";

console.log(text.toWellFormed());

Output


Use Case

Cleaning corrupted text data.


15. String trim()

Purpose

Removes spaces from beginning and end.

Example

let email = "  user@gmail.com  ";

console.log(email.trim());

Output

user@gmail.com


16. String trimStart()

Purpose

Removes spaces only from beginning.

Example

let text = "   Hello";

console.log(text.trimStart());

Output

Hello


17. String trimEnd()

Purpose

Removes spaces only from end.

Example

let text = "Hello   ";

console.log(text.trimEnd());

Output

Hello


18. String padStart()

Purpose

Adds characters at the beginning until desired length.

Example

let orderId = "123";

console.log(orderId.padStart(6,"0"));

Output

000123

Real-Time Example

Generating invoice numbers.


19. String padEnd()

Purpose

Adds characters at the end.

Example

let code = "JS";

console.log(code.padEnd(5,"*"));

Output

JS***


20. String repeat()

Purpose

Repeats a string multiple times.

Example

let star = "*";

console.log(star.repeat(5));

Output

*****

Real-Time Example

Printing separators.


21. String replace()

Purpose

Replaces first matching occurrence.

Example

let sentence = "I love Java. Java is powerful.";

console.log(sentence.replace("Java","JavaScript"));

Output

I love JavaScript. Java is powerful.

Note

Only first occurrence is replaced.


22. String replaceAll()

Purpose

Replaces all matching occurrences.

Example

let sentence = "Java Java Java";

console.log(sentence.replaceAll("Java","JS"));

Output

JS JS JS


23. String split()

Purpose

Converts string into array.

Example

let skills = "HTML,CSS,JavaScript";

let result = skills.split(",");

console.log(result);

Output

["HTML", "CSS", "JavaScript"]

Split by Space

let sentence = "Learning JavaScript Daily";

console.log(sentence.split(" "));

Output

["Learning","JavaScript","Daily"]


Quick Comparison Table

Method Purpose
length Count characters
charAt() Get character
charCodeAt() Unicode value
codePointAt() Unicode code point
concat() Join strings
at() Access character (supports negative index)
[ ] Access character
slice() Extract part of string
substring() Extract text (no negative index)
substr() Extract by length (deprecated)
toUpperCase() Convert to uppercase
toLowerCase() Convert to lowercase
isWellFormed() Check valid Unicode
toWellFormed() Fix invalid Unicode
trim() Remove spaces both sides
trimStart() Remove left spaces
trimEnd() Remove right spaces
padStart() Add characters at beginning
padEnd() Add characters at end
repeat() Repeat string
replace() Replace first match
replaceAll() Replace all matches
split() Convert string to array

References:
https://www.w3schools.com/js/js_string_methods.asp