• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Basics / JavaScript Strings Explained

JavaScript Strings Explained

JavaScript Strings Explained

In JavaScript, Strings are values made up of text and can contain letters, numbers, symbols, punctuation, and even emojis!

Single and Double Quotes in JavaScript Strings

Strings in JavaScript are contained within a pair of either single quotation marks ” or double quotation marks “”. Both quotes represent Strings but be sure to choose one and STICK WITH IT. If you start with a single quote, you need to end with a single quote. There are pros and cons to using both IE single quotes tend to make it easier to write HTML within JavaScript as you don’t have to escape the line with a double quote.

JavaScript String Methods and Properties

Strings have their own built-in variables and functions, also known as properties and methods. Here are some of the most common ones.

JavaScript String Length

A string’s length property keeps track of how many characters it has.

// Example
"caterpillar".length;


// Output
11

toLowerCase Method

A string’s toLowerCase method in JavaScript returns a copy of the string with its letters converted to lowercase. Numbers, symbols, and other characters are not affected.

// Example
"THE KIDS".toLowerCase();

// Output
"the kids"

toUpperCase Method

A string’s toUpperCase method returns a copy of the string with its letters converted to capitals. Numbers, symbols, and other characters are not affected.

trim Method

A string’s trim method returns a copy of the string with beginning and ending whitespace characters removed.

// Example
"   but keep the middle spaces   ".trim();

// Output
"but keep the middle spaces"

Source

https://www.javascript.com/learn/strings

Basics

Related Snippets:

  • Bitwise Operators in JavaScript
  • Arithmetic Operators in JavaScript
  • How To Loop Through All The Entries In An Array Using JavaScript
  • Default Function Parameters

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers