String includes() method in JavaScript

Explore what is string includes() method in JavaScript and how to use it.

Keep reading to unlock the potential of JavaScript string includes() method.

Are you ready to discover the power of string includes() method in JS?

Let’s start to dive into this comprehensive guide that illuminates how to determine if a string contains a specified substring.

What is JavaScript string includes() method?

The includes() method in JavaScript is a part of the String.prototype and is used to determine whether one string may be found within another string.

Its purpose is to check if a certain sequence of characters, or a “substring”, appears within the string you’re working with.

It provides a boolean outcome: true if the given string is detected, and false if it’s not found.

Syntax

string.includes(searchString, startingposition)

Parameters

searchString (Required)

The sequence of characters or string you’re looking for.

startingPosition (Optional)

This is the position from where you can specify at which character position in your string to start the search. If you don’t provide this, the search starts from the beginning of the string.

Return value

The includes() method will then return either true or false. It returns true if the substring is found within your string, and false if it’s not.

One important thing to note is that this method is case-sensitive. This means it treats lowercase and uppercase letters as different characters.

For instance, if your string is “Itsourcecode” and you check if it includes “itsourcecode,” it will return false because of the difference in case.

Supported browser

✔Chrome

✔Edge

✔Firefox

✔Opera

✔Safari

How to use the includes() method in JavaScript?

The includes() method in JavaScript is used to check if a string contains a specified string. It returns a boolean value – true if the string is found, otherwise false.

Here’s how you can use it:

let samplestr = "Hi, Welcome to Itsourcecode!";
console.log(samplestr.includes("Hi"));

In this example, includes() is used to check if the string “Hi” is included in the string “Hi, Welcome to Itsourcode.”

Since “Hi” is indeed part of “Hi, Welcome to Itsourcecode,” the method returns:

true

You can also specify a second argument to includes(), which is the position in the string at which to start searching:

let samplestr = "Hi, Welcome to Itsourcecode!";
console.log(samplestr.includes("Itsourcecode", 15)); ✅ // Outputs: true
console.log(samplestr.includes("Itsourcecode", 17)); ✅// Outputs: false

In the first console log, includes() starts searching from position 15 and finds “Itsourcecode.”

In the second console log, it starts searching from position 4 and does not find “Itsourcecode,” so it returns false.

Remember that includes() is case-sensitive. For example, “Itsourcecode”.includes(“itsourcecode”) would return false.

If you want to perform a case-insensitive search, you can convert both strings to lower case:

let samplestr = "Hi, Welcome to Itsourcecode!";
console.log(samplestr.toLowerCase().includes("itsourcecode".toLowerCase())); 

In this example, both the original string and the search string are converted to lowercase before calling includes(), so it correctly finds “Itsourcecode” in “Hi, Welcome to Itsourcecode!” and returns true.

Here’s another example of how to use the includes() method:

const samplestr = "Hi, Welcome to Itsourcode!.";

console.log(samplestr.includes("to")); // Outputs: true

console.log(samplestr.includes("Welcome")); // Outputs: true

console.log(samplestr.includes("Source")); // Outputs: false

console.log(samplestr.includes("Hi", 1)); // Outputs: false

console.log(samplestr.includes("ITSOURCECODE")); // Outputs: false

console.log(samplestr.includes("")); // Outputs: true

Complete output:

true
true
false
false
false
true

Frequently Asked Questions (FAQs)

Is includes() a string method in JavaScript?

Yes, includes() is indeed a method that you can use with strings in JavaScript. It’s used to check if a certain string, the one you’re looking for, is found within another string.

It’s case-sensitive, which means it treats uppercase and lowercase letters as different characters.

If it finds the string you’re looking for, it returns true. If it doesn’t find it, it returns false.

Can I use JS includes?

Absolutely! The includes() method is a standard part of JavaScript and you can use it in any modern web browser, including Chrome, Firefox, Safari, Edge, and Opera.

However, if you’re using Internet Explorer 11 or an earlier version, please note that includes() is not supported.

What is include and contains in JavaScript?

The includes() is a versatile method that works with both strings and arrays in JavaScript.

When used with a string, it checks if the string contains a certain substring.

When used with an array, it checks if the array contains a certain element. As for contains(), there’s no such method in JavaScript.

If you want to check if a string contains a certain substring or if an array contains a certain element, you would use includes().

Conclusion

In conclusion, the includes() method in JavaScript is used to check if a string contains a specified substring, returning a boolean value based on the result.

This method is case-sensitive and can start searching from a specified position in the string. It’s supported in all modern browsers and is an essential part of string manipulation in JavaScript.

We are hoping that this article provides you with enough information that help you understand the string includes JavaScript.

If you want to dive into more JavaScript topics, check out the following articles:

Thank you for reading Itsourcecoders 😊.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.

Leave a Comment