DEV Community

loading...

10 javascript features

NayemulSCode
Updated on ・3 min read

topic-1: truthy falsy

1.if value is 0 then falsy, otherwise truthy
like:
const digit = 0; //false
const digit = 10// true

2.if string is empty then falsy otherwise truthy
like:
const myString = ""; //false
const myString = " " //withe white space but ture
cosnt myString = "Nayemul "; //true

3.value is false
like:
const name; // false
const name = null // false
const name = false // false
const name = NaN //false

4.value is truthy
const name = " ";
const name = [];
const name = {};

topic-2: undefine

  1. declare a variable but not initilize value like: let title; console.log(title) // result is: undefine

2.when functions are not return vlaue
like:
function add(value1, value2){
console.log(value1+value2); // result: 30
}
const add(15,15)
console.log(add) // resutt: undefine

topic-3: compare the value with (==)

phase1:
const digit = 5;
const myString= "5";
if(digit == myString)
result will be true, beacuse (==) compare between two different vlaue.
in this case, one is 5 another is string 5
but value is equal so result is true;

phase2:
const digit = 1;
const boolean = true;
if(digit == boolean)
result will be true, beacuse (==) compare between two different vlaue.
in this case, one is 1 another is bool vlaue (true), we know that true=1.
but value is equal so result is true;

phase3:
const digit = 0;
const boolean = false;
if(digit == boolean)
result will be true, beacuse (==) compare between two different vlaue.
in this case, one is 0 another is bool vlaue (false), we know that false=0
but value is equal so result is true;

topic-4: compare vlaue with type (===)
phase1:
const digit = 5;
const myString= "5";
if(digit === myString)
result will be false, beacuse (===) compare between two different value with thire types.
in this case, one is 5(type:number) another is string 5(type:string)
but value is equal but type is not equal so result is false;

phase2:
const digit = 1;
const boolean = true;
if(digit == boolean)
result will be false, beacuse (===) compare between two different value with thire types.
in this case, one is 1(type:number) another is bool true(type:bool)
but value is equal but type is not equal so result is false;

phase3:
const digit = 0;
const boolean = false;
if(digit == boolean)
result will be false, beacuse (===) compare between two different value with thire types.
in this case, one is 0(type:number) another is bool flase(type:bool)
but value is equal but type is not equal so result is false;

topic-5: closure
the closure is the combination of function that gives access to outer function scope from an inner function
closure normally use for data hiding and encapsulation
clouser scope:
ecery closure have three scopes
1.loacl scope(own scope)
2.outer functions scope
3.global scope

//global scope
function Counter(){
let count = 0;
return function(){ //outer scope
//local scope
count++;
return count;
}
}
const counter1 = Counter();
console.log(counter1());
console.log(counter1());
const counter2 = Counter();
console.log(counter2());

topic: 6

syntax: variable_name.concat(string1,string2,stringN);

const myString1 = “Hello”;
const myString2 = “Programmer”;
myString.concat(‘ ‘,myString2);
result: Hello Programmer
const myString1 = “Hello”;
const myString2 = “Programmer”;
const myString3 = “Bangladesh”
myString.concat(‘ ‘,myString2,’ ‘, myString3);
result: Hello Programmer Bangladesh

topic: 7
how you determine whether one string may be found within another? just write
const myString = “i love my Mother”;
const match = “love”;
myString.includes(match);//return boolean, true or false
result: true // mean founded

Discussion (0)