Javascript
/
Types
- 1 Fundamentals 11
-
Hello World S
-
Code structure S
-
Use strict S
-
Variables S
-
Data types S
-
Type conversions S
-
Maths S
-
Comparitions S
-
Conditional S
-
Loops S
-
Functions S
- 2 Testing 2
-
Mocha S
-
Nested describe S
- 3 Objects 4
-
Basics S
-
Reference S
-
Methods S
-
Constructor S
- 4 Types 5
-
Primitives S
-
Numbers S
-
Strings S
-
Arrays S
-
Json S
- 5 Classes 3
-
Constructor S
-
Binding S
-
Inheritance S
S
R
Q
Javascript Types Strings
With backsticks we can embed any expression, or span multiple lines let str = 'World' console.log(`Hello ${str}`)EmbedBacksticks
Backsticks
With backsticks we can embed any expression into the string.
/**
* Backsticks quotes
*
* Embed any expression into the string
* Span multiple lines
* Special characters start with a backslash character
*/
let str = 'World';
console.log(`Hello ${str}`); // Hello World
let guestList = `Guests:
* John
* Pete
* Mary
`;
console.log(guestList); // John Pete Mary
console.log('Object\'s properties'); // Object's properties
console.log('One backslash \\'); // One backslash \
Substring
Modern Javascript has methods like include, startsWith.
/**
* Substring methods
*
* includes, startsWith, slice
*/
console.log("Widget with id".includes('id')); // true
console.log('Widget'.includes('id', 2)); // false
console.log('Widget'.startsWith('Wid')); // true
console.log('Widget'.endsWith('get')); // true
console.log('Widget'.slice(0, 3)); // Wid
console.log('Widget'.charAt('0')); // W
console.log('Widget'.indexOf('id')); // 1
console.log('Widget with id'.indexOf('Widget')); // 0
console.log('Widget with id'.indexOf('widget')); // -1
console.log('Widget with id'.indexOf("id")); // 1
console.log('Widget with id'.indexOf('id', 2)); // 12
➥ Questions
Last update: 48 days ago