Skip to content

Instantly share code, notes, and snippets.

@KinoAR

KinoAR/Strings.js

Last active Nov 1, 2016
Embed
What would you like to do?
//=============================================================================
// Strings
//=============================================================================
//String Examples
//String Literals
//Double quotes
var string1 = "Hello World";
//Single quotes
var string2 = 'Hello World';
//Template Literals
var templateLiteralString = `Hello World`;
//Both String Literals and Template Literals can use string methods.
//Repeat
console.log(string1.repeat(2)); //Hello WorldHello World
//Includes
console.log(string1.includes("Hello")); //True
console.log(string1.includes("World")); //True
//IndexOf
console.log(string1.indexOf('H')); //0
console.log(string1.indexOf('W')); //6
//StartsWith
console.log(string1.startsWith("Hello")); //True
console.log(string1.startsWith("World")); //False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment