Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Js Strings in JavaScript

Js Strings in JavaScript

? JavaScript Strings

Strings in JavaScript represent sequences of characters used to store and manipulate text.


What is a String?

  • A string is a sequence of characters enclosed in single quotes (''), double quotes (""), or backticks (``).

  • Examples:

let str1 = "Hello, world!";let str2 = 'JavaScript is fun.';let str3 = `Template literals allow embedding variables.`;

Key Characteristics

  • Strings are immutable — once created, they cannot be changed (but you can create new strings from existing ones).

  • Strings have a length property indicating the number of characters.

console.log(str1.length); // 13

Creating Strings

let singleQuote = 'Hello';let doubleQuote = "World";let backtick = `Hello World`;

Common String Operations

  • Concatenation:

let greeting = "Hello, " + "World!"; // "Hello, World!"
  • Template literals:

let name = "Alice";let message = `Hello, ${name}!`; // "Hello, Alice!"
  • Access characters:

console.log(str1[0]); // 'H'
  • Escape characters:

let quote = "He said, \"JavaScript is awesome!\"";

String Methods

JavaScript provides many methods to work with strings, like:

  • toUpperCase()

  • toLowerCase()

  • indexOf()

  • slice()

  • split()

  • replace()

  • trim()

  • ...and many more!


Example:

let text = "  JavaScript is great!  ";console.log(text.length);             // 22console.log(text.trim());             // "JavaScript is great!"console.log(text.toUpperCase());     // "  JAVASCRIPT IS GREAT!  "console.log(text.indexOf("is"));     // 11console.log(text.slice(2, 12));      // "JavaScript"

If you want, I can help you explore specific string methods or advanced string handling!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql