MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
String Basics0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
6.1String Basics6.2Common String Methods6.3Template Literals (Basics)
HomeTutorialsJavaScript for BeginnersString Basics
Common String Methods

String Basics

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Text is one of the most fundamental data formats in software. In JavaScript, strings represent sequences of UTF-16 character codes. Understanding string indexing, length, and immutability is essential for building web interfaces.


1. Creating Strings in JavaScript

JavaScript supports three different quotation delimiters for string literals:

1// 1. Single Quotes
2const city = 'New Delhi';
3 
4// 2. Double Quotes
5const country = "India";
6 
7// 3. Backticks (Template Literals - ES6)
8const institute = `MSK Institute`;

Escaping Special Characters (\):

If a string contains quotation marks inside it, escape them with a backslash \:

1const quote = "She said, \"JavaScript is amazing!\"";
2const contraction = 'It\'s a sunny day';

Useful Escape Sequences:

  • \n : Newline (line break)
  • \t : Tab indentation
  • \\ : Literal backslash

2. String Length & Zero-Based Indexing

Strings behave similarly to arrays: characters are indexed starting at 0:

1String: "M S K"
2Index: 0 1 2

3. The Golden Rule: Strings are Immutable!

[!IMPORTANT] Strings in JavaScript are 100% IMMUTABLE. Once created in memory, individual characters inside a string cannot be changed in place!
1let str = "Hello";
2str[0] = "J"; // Trying to change "H" to "J"
3 
4console.log(str); // "Hello"! (Unchanged! JavaScript silently ignores this assignment)

How to "Change" a String:

To change a string, you must create and assign a brand new string:

1let str = "Hello";
2str = "J" + str.slice(1);
3console.log(str); // "Jello"

4. Iterating Through Strings

Because strings are iterable, you can loop through their characters using a for loop or for...of:

1const word = "CODE";
2 
3for (const char of word) {
4 console.log(char);
5}
6// Outputs:
7// C
8// O
9// D
10// E

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What index number represents the very first character of a string in JavaScript?
Question 2
What is the result of running let s = "Hello"; s[0] = "Y"; console.log(s);?
Question 3
How do you get the total number of characters in a string named msg?
Question 4
Which modern method introduced in ES2022 allows accessing the last character of a string using negative indexing (e.g. str.at(-1))?
Question 5
What escape sequence inserts a line break (new line) inside a string literal?
Next Lesson

Common String Methods

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Loop Control: break, continueCommon String Methods

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext