HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to JavaScriptVariables (let / const)Data TypesOperatorsStringsArraysObjectsConditions (if / else)Loops (for / while)FunctionsArrow Functions (=>)Array Methods (map / filter / reduce)
REFERENCE
📖 Overview
🖥️ Output & Console
📦 Variables
🔢 Numbers & Math
✍️ String
.lengthtoUpperCase() / toLowerCase()trim()slice()split()replace() / replaceAll()includes() / indexOf()
📋 Array
🗂️ Object
🔁 Condition & Loop
🧩 Function
🔄 Type & Conversion
JavaScript›REFERENCE›String
✍️

String

Text length, conversion, slicing, splitting, and searching.

CommandDescription
.lengthReturns the number of characters.
toUpperCase() / toLowerCase()Converts to uppercase / lowercase.
trim()Removes leading and trailing whitespace.
slice()Extracts a part of the text.
split()Splits the text into an array.
replace() / replaceAll()Replaces a part with something else.
includes() / indexOf()Finds the presence/position of a part.

.length

Try it yourself →

Returns the number of characters.

Syntax

text.length

Description

Returns how many characters the text consists of (property, not a method — no parentheses).

Returns

Length (number).

Example

console.log("hello".length);

Expected output

5

When to use?

Password length, character limit check.

toUpperCase() / toLowerCase()

Try it yourself →

Converts to uppercase / lowercase.

Syntax

text.toUpperCase() · text.toLowerCase()

Description

Returns a new text; does not modify the original.

Example

console.log("HexLibrary".toUpperCase());
console.log("HexLibrary".toLowerCase());

Expected output

HEXLIBRARY
hexlibrary

When to use?

Comparison ignoring case differences (email, search).

trim()

Try it yourself →

Removes leading and trailing whitespace.

Syntax

text.trim()

Description

Cleans up spaces/newlines at the beginning and end of the text.

Example

console.log("   space   ".trim());

Expected output

space

When to use?

Cleaning unwanted spaces in form inputs.

slice()

Try it yourself →

Extracts a part of the text.

Syntax

text.slice(start, end)

Description

Returns the slice from start to end (end exclusive). Negative index counts from the end.

Returns

Subtext (string).

Example

console.log("HexLibrary".slice(0, 3));
console.log("HexLibrary".slice(-3));

Expected output

Hex
ary

When to use?

Taking the first N characters, slicing extensions/suffixes.

split()

Try it yourself →

Splits the text into an array.

Syntax

text.split(separator)

Description

Splits the text by the given separator and returns the pieces as an array.

Returns

Array of pieces.

Example

console.log("a,b,c".split(","));

Expected output

[ 'a', 'b', 'c' ]

When to use?

Splitting a CSV line into fields, a sentence into words.

replace() / replaceAll()

Try it yourself →

Replaces a part with something else.

Syntax

text.replace(old, new)

Description

replace changes the first match, replaceAll changes all matches. Returns new text.

Example

console.log("leo leo".replace("leo", "emma"));
console.log("leo leo".replaceAll("leo", "emma"));

Expected output

emma leo
emma emma

When to use?

Text cleaning, filling templates.

includes() / indexOf()

Try it yourself →

Finds the presence/position of a part.

Syntax

text.includes(part) · text.indexOf(part)

Description

includes returns true/false. indexOf gives the position (-1 if not found).

Example

console.log("education".includes("cat"));
console.log("merhaba".indexOf("hab"));

Expected output

true
3

When to use?

Searching, checking whether a word appears in the text.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code