JavaScript Muggle: String

let text = 'I like coffee';
console.log(text.length) // 13
console.log(text[0]); // 'I'
let and = 'and';
let tea = 'tea';
let newText = text + and + tea;
console.log(newText); // 'I like coffeeandtea'
let textWithSpace = text + ' ' + and + ' ' + tea;
console.log(textWithSpace) // 'I like coffee and tea'
// to obtain a piece of string
text.substring(0,6); // 'I like'
text.slice(0,6); // 'I like'
//split text
text.split(" "); ['I', 'like', 'coffee']
//character at index 2
text.charAt(2); // 'l'
text.startsWith('I'); // true
text.endsWith('like'); // false
// turn a string characters into lowercase/uppercase characters
'my name is Marshal'.toUpperCase(); // 'MY NAME IS MARSHAL'
'my name is Marshal'.toLowerCase(); // 'my name is marshal'
let name = 'Jermaine Lamarr Cole';
name[2]; // 'r'
name[0]; // 'J'

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

//platform.twitter.com/widgets.js from Twitter https://twitter.com/envus_motors

How to Register a Vue3 Global Component

Let’s build your first Augmented Reality (AR) enabled webpage

JavaScript Arrow Functions (Beginner Friendly)

Destructuring in javascript

Algorithm — fibonacciNum

Instantly Retrieve Medium’s articles with React & Recoil in three easy steps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aktan Abdygaziev

Aktan Abdygaziev

More from Medium

Functions & Function Declarations in Javascript

JavaScript Events

3 Type Javascript Function

Array Iteration Methods: .map()