Skip to content

Instantly share code, notes, and snippets.

View ranamahmud's full-sized avatar
🎯
Focusing

Md Rana Mahmud ranamahmud

🎯
Focusing
View GitHub Profile
var sum = function(a, b){
var res = a + b;
return res;
}
sum(5,10);
// 15
var sumDefault = function(a, b = 10){
var res = a + b;
return res;
}
// normal funciton
const double = function(num){
return num*2;
}
// converted to arrow function
num => num * 2
num => num * 2
[1,2,3].map(num => num * 2);
// [2, 4, 6]
// This is a single line comment
/* This is a comment spanning multiline.
You should be careful about writing comment. */
var num1 = 50;
var num2 = 50;
// This is a single line comment
/* This is a comment spanning multiline.
You should be careful about writing comment. */
var num1 = 50;
var num2 = 50;
// error free code
try {
alert("Hello World");
} catch (err) {
alert("Error found");
}
// code with error
try {
console.log(typeof(19));
// number
console.log(typeof(undefined));
// undefined
typeof("Hello World!");
"string"
console.log(typeof true);
// boolean
console.log(typeof {});
// object
// constants
console.log(Math.PI)
// 3.141592653589793
console.log(Math.LN2)
// 0.6931471805599453
Math.sqrt(9)
// 3
Math.pow(3, 2)
// 9
Math.abs(-9)
const year = 2020
var result;
if (year>2019){
result = "Yes";
} else{
result = "No";
}
console.log(result)
//Yes
var result = year > 2019 ? "Yes" : "No";
var name = " JavaScript";
var language = " JavaScript ";
console.log(language);
// JavaScript
var languageBoth = language.trim();
console.log(languageBoth)
// JavaScript
var languageStart = language.trimStart();
console.log(languageStart)
// JavaScript
// declare an array
var fruits = ["apple", "orange", "banana", "pineapple"]
// loop over with items
fruits.forEach(function(fruit){
console.log(fruit);
})
// output
// apple
// orange
// banana