Explain Implicit Type Coercion in JavaScript with example
Posted By Rezaul Karim | JavaScript No Comments
Implicit type coercion in JavaScript is automatic conversion of value from one data type to another. It takes place ...
JavaScript ES6 Cheat Sheet with example. ECMAScript 6 – ES6 is the standard specification of JavaScript Which Introduced in 2015 (ES2015). Here’s a cheatsheet to show you .
Recommended: Test your JavaScript knowledge – JavaScript quiz!
const sum = (a,b) => a + b; console.log(sum(2,6)) // prints 8
function print(a = 5) { console.log(a) } print() // prints 5 print(22) // prints 22
let a = 3 if (true) { let a = 5 console.log(a) // prints 5 } console.log(a) // prints 3
// can be assigned only once const a = 55 a = 44 // throws an error
console.log( `This is a multi-line string` )
const names = "World" const message = `Hello ${names}` console.log(message) // prints "Hello World"
Recommended: Test your programming knowledge – Programming quiz!
const byte = 2 ** 8 // expected result = 256 // Same as: Math.pow(2, 8)
const a = [ 1, 2 ] const b = [ 3, 4 ] const c = [ ...a, ...b ] console.log(c) // [1, 2, 3, 4]
console.log('scripts'.includes('s')) // prints true console.log('scripts'.includes('m')) // prints false // The includes() method is case sensitive. For example, the following expression returns false: console.log('scripts'.includes('S')) // prints false
console.log('scripts'.startsWith('sc')) // prints true console.log('scripts'.startsWith('rip')) // prints false
console.log('st'.repeat(3)) // prints "ststst"
let [a,b] = [3,7]; console.log(a); // 3 console.log(b); // 7
let obj = { a: 77, b: 66 }; let { a,b } = obj; console.log(a); // 77 console.log(b); // 66
const a = 2 const b = 5 const obj = { a, b } // Before es6: // obj = { a: a, b:b } console.log(obj) // prints { a:2, b:5 }
const obj1 = { a: 1 } const obj2 = { b: 2 } const obj3 = Object.assign({}, obj1, obj2) console.log(obj3) // { a: 1, b: 2 }
Promise .then((result) => { ... }) .catch((error) => { ... }) .finally(() => { /* logic independent of success/error */ }) /* The handler is called when the promise is fulfilled or rejected. */
const a = { firstName: "FirstName", lastName: "LastName1", } const b = { ...a, lastName: "LastName2", canSing: true, } console.log(a) //{firstName: "FirstName", lastName: "LastName1"} console.log(b) /* {firstName: "FirstName", lastName: "LastName2", canSign: true} */ /* great for modifying objects without side effects/affecting the original */
const Person = { name: "Rezaul karim", age: 23, sex: "male", maritalstatus: "single", address: { country: "BD", state: "Dhaka", city: "N.Ganj", pincode: "123456", }, }; const { address: { state, pincode }, name } = Person; console.log(name, state, pincode) // Rezaul Karim Dhaka 123456 console.log(city) // ReferenceError
const obj = { a: 5, b() { console.log('b') } } obj.b() // prints "b"
const obj = { firstName: "FirstName", lastName: "LastName1", age: 23, country: "Bangladesh", }; const entries = Object.entries(obj); console.log(entries) /* prints [ ['firstName', 'FirstName'], ['lastName', 'LastName'], ['age', 23], ['country', 'Bangladesh'] ]; */
Here’s the ECMAScript 6 cheat sheet list. Hope its helps you to grow up your skills.
Find it helpful? Please share with your friends and Read my others article about coding and programming, Tips, Productivity , Resources etc…
Discuss a project or just want to say hi? My Inbox is open for all.