A string literal is normally delimited by the ' or " character, and can normally contain almost any character. Common convention differs on whether to use single quotes or double quotes for strings. Some developers are for single quotes (Crockford, Amaram, Sakalos, Michaux), while others are for double quotes (NextApp, Murray, Dojo). Whichever method you choose, try to be consistent in how you apply it.

Due to the delimiters, it's not possible to directly place either the single or double quote within the string when it's used to start or end the string. In order to work around that limitation, you can either switch to the other type of delimiter for that case, or place a backslash before the quote to ensure that it appears within the string:

When the end is provided, they are extracted up to, but not including the end position.

"hello".slice(1,3);// "el"

Slice allows you to extract text referenced from the end of the string by using negative indexing.

"hello".slice(-4,-2);// "el"

Unlike substring, the slice method never swaps the start and end positions. If the start is after the end, slice will attempt to extract the content as presented, but will most likely provide unexpected results.

When the end is provided, they are extracted up to, but not including the end position.

"hello".substring(1,3);// "el"

substring always works from left to right. If the start position is larger than the end position, substring will swap the values; although sometimes useful, this is not always what you want; different behavior is provided by slice.