- OBJECTS
- Basics
- Reference
- Methods
- Constructor
- FUNDAMENTALS
- Hello World
- Code Structure
- Use Strict
- Variables
- Data Types
- Type Conversions
- Maths
- Comparitions
- Conditional
- Loops
- Functions
- TESTING
- Mocha
- Nested Describe
- TYPES
- Primitives
- Numbers
-
Strings
- Arrays
- Json
- DESIGN PATTERN
- Observer Pattern
- CLASSES
- Constructor
- Binding
- Inheritance
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
Last update: 531 days ago