Skip to content

Instantly share code, notes, and snippets.

View LearningMaterial's full-sized avatar

Ashiqur Rahman LearningMaterial

View GitHub Profile
@LearningMaterial
LearningMaterial / a) understandJS.md
Last active February 28, 2019 13:29
Notes of Javascript_The_Weird_Parts

Javascript Understanding The Weird Parts

for (var i = 0; i < 10; i++) {
setTimeout(() => {
console.log(`The number is ${i}`);
}, 1000);
}
for (var i = 0; i < 10; i++) {
(function () {
var currentValueOfI = i;
setTimeout(() => {
console.log(`The number is ${currentValueOfI}`);
}, 1000);
})();
}
false == "0" // true
// false gets coerced to 0
// "0" gets coerced to 0
// 0 == 0 is true 

false == 0 // true
// false gets coerced to 0
// 0 == 0 is true
function calculateBill(total, tax, tip) {
return total + total * tax + total * tip;
}
var result = calculateBill(100, 0.13, 0.15);
console.log(result);
function calculateMyBill(total, tax, tip) {
return total + total * tax + total * tip;
}
var result = calculateMyBill(100);
console.log(result);
function calculateBill(total, tax = 0.13, tip = 0.15) {
return total + total * tax + total * tip;
}
const result = calculateBill(100);
console.log(result);
function addNumber(num1, num2 = 20, num3 = 10) {
return num1 + num2 + num3;
}
console.log(addNumber(10));
console.log(addNumber(10, 40, 30));
const names = ["sakib", "tamim", "Riad"];
const fullNames = names.map(function(name) {
return `${name}`;
});
console.log(fullNames);
const names = ["sakib", "tamim", "Riad"];
const fullNames = names.map(name => {
return `${name}`;
});
console.log(fullNames);