🌰Strings

In JavaScript, a string is a sequence of characters enclosed in quotes. You can use single or double quotes to create a string, as long as you use the same type of quotes to enclose the string.

Here are some examples of strings in JavaScript:

const name = 'John';
const message = "Welcome to my adventure game!";
const error = 'It\'s not possible to go that way';

You can also use string concatenation to combine strings together. For example:

const greeting = 'Hello ' + name + ', ' + message;

This would create a new string with the value "Hello John, Welcome to my adventure game!"

There are many methods available for working with strings in JavaScript. Here are a few examples:

  • length: Returns the length of a string (i.e. the number of characters)

  • toUpperCase(): Returns a new string with all characters in uppercase

  • toLowerCase(): Returns a new string with all characters in lowercase

  • substring(start, end): Returns a new string containing the characters from a string between the specified start and end indices

Last updated