Last active
October 8, 2018 05:52
-
-
Save ajitStephen/256b8af4fb084ea8b568ba89fc4be686 to your computer and use it in GitHub Desktop.
Cool ways of logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const foo = { name: "shyam", age: "10", code: false }; | |
const coo = { name: "ram", age: "10", code: true }; | |
const doo = { name: "kaam", age: "10", code: false }; | |
//show variable name also | |
console.log({ foo, coo, doo }); | |
// css | |
console.log("%c Test", "color:orange;font-weight:900;"); | |
// TABLE | |
console.table([foo, coo, doo]); | |
// time trace | |
console.time("looper"); | |
let i = 0; | |
while (i < 1000000) { | |
i++; | |
} | |
console.timeEnd("looper"); | |
// Stack trace log. | |
const test = () => console.trace("Look at me now!"); | |
test(); | |
test(); | |
test(); | |
// string concatenation | |
function boyAge(str, age) { | |
const ageStr = age > 5 ? "old" : "young"; | |
return `${str[0]}${ageStr} at ${age} years`; | |
} | |
const beta = boyAge`This boy's age is ${4}`; | |
console.log(beta); | |
// spread syntax | |
const pikachu = { name: "Pikachu" }; | |
const stats = { height: "50cm", weight: "10kg", alpha: false }; | |
// want to merge pikachu & stats | |
const newPikachu = Object.assign(pikachu, stats); | |
// OR better | |
const newPikachu1 = { ...pikachu, ...stats }; | |
console.log({ newPikachu, newPikachu1 }); | |
// spread works same for arrays | |
// best looping techniques | |
// reduce, filter, map | |
// Promises | |
// instead of chaining .then() use async & await |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment