For #1: if(isGirl) is not a shorthand for if(isGirl === true) because the first condition will always pass if the value is truthy whereas later will only pass if the value is boolean true.
For #3: Arrow function is not a shorthand for the traditional function. Because arrow functions are lexical meaning this inside an arrow function will only have lexical scope. So it can not be bind, call or applied against another context.
Ebrahim Hasan is a full stack web developer, currently working as a freelancer on freelancer.com, he is a co-owner of a swedish and an Egyptian company.
But note that this is not a traditional for loop, this is a "for of", it even can loop through Strings (instead of converting a string to an array or using a for with the length)
I think the only advantage that I see to use the for loop is having one common way to loop through elements, or if you have a function that can have different iterable object types, example:
Ebrahim Hasan is a full stack web developer, currently working as a freelancer on freelancer.com, he is a co-owner of a swedish and an Egyptian company.
This is fire!! 🔥🔥🔥 I've bookmarked this and will share it out for sure! Appreciate all the edit suggestions in the comments as well! Great work Ayekple!
We're a place where coders share, stay up-to-date and grow their careers.
12 and 15 is well-known to be quite dangerous, that is why rather than
This is safer
Without
??, I do have to write my own utility function sometimes.Thanks
For #1:
if(isGirl)is not a shorthand forif(isGirl === true)because the first condition will always pass if the value is truthy whereas later will only pass if the value is boolean true.For #3: Arrow function is not a shorthand for the traditional function. Because arrow functions are lexical meaning
thisinside an arrow function will only have lexical scope. So it can not be bind, call or applied against another context.For #12 and #15 see this commented
Also, the arrow function in this case isn't hoisting,
function expressions (aka the longhand) will hoist.
But note that this is not a traditional for loop, this is a "for of", it even can loop through Strings (instead of converting a string to an array or using a for with the length)
I think the only advantage that I see to use the for loop is having one common way to loop through elements, or if you have a function that can have different iterable object types, example:
const loopThrough = (object) => {
for(const n of object) {
console.log(n);
}
};
loopThrough("hello");
loopThrough(["h","e","l","l","o"]);
loopThrough(new Set([1, 2, 3, 4, 5]));
// Longhand
const quantity = parseInt("250")
const price = parseFloat("432.50")
// Shorthand
const quantity = +"250" // converts to int
const price = +"432.50" // converts to float
I have a habbit of using parseInt parseFloat everytime.I would surely follow this shorthand.
Because
forEachdoes not return anything. You might need to use the returned value somewhere out of your callback.Both forEach and for of can be used, forEach is used in arrays while for of can be used in arrays,maps,set or any iterable member objects.
I guess 10. should be
Thanks
Also logically, wouldn't you want to subtract the discount?
This is fire!! 🔥🔥🔥 I've bookmarked this and will share it out for sure! Appreciate all the edit suggestions in the comments as well! Great work Ayekple!