Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

difference between == and === in javascript

0 == false   // true
0 === false  // false, because they are of a different type
1 == "1"     // true, automatic type conversion for value only
1 === "1"    // false, because they are of a different type
null == undefined // true
null === undefined // false
'0' == false // true
'0' === false // false
Comment

Difference Between =, == And === In JavaScript

var number = 100;  // Here number variable assigned using = 

if (number == 100)
  // Here Comparision between two values using ==.
  // This will not check datatype irrespective of datatype it will do comparision  
  console.log("Both are equal");

else  
  console.log("Both are not equal");

if(number === "100")  //Here Comparision between two values using ===.
  // This will check datatype if it is same then it will do comparision otherwise it will go to else part  
  console.log("Both are equal");

else  
  console.log("Both are not equal");

/*
Output will be :- 
	Both are equal
	Both are equal
*/
Comment

difference between || and ?? in js

// The main difference is that nullish coalescing(??) operator will only
// give the result as the right operand only if the left operand is either null or undefined.

// Whereas the OR(||) operator will give the result as right operand 
// for all the falsy values of the left operand.

const a = 0;
// a || 10 --> Will result in 10, as || operator considers 0 as falsy value and resulting the right side operand
console.log(`a || 10 = ${a || 10}`);
// a ?? 10 --> Will result in 0, as ?? operator considers 0 as truthy value and resulting the left side operand
console.log(`a ?? 10 = ${a ?? 10}`);
Comment

difference between =, == and === in javascript

/*
= operator in javascript is called as assign operator. It is used to assign
value to a variable, it is used as: */
variable = "value"
/*      ^^^
here, as you can see, it is saying that variable should be assigned(=) the value
"value" */

/*
== operator in javascript is called the equals operator. It is used to compare
equals between two values, ignoring their types(number, string, boolean, etc.),
it is used as: */
   (5 == "5") // true
/* ^^^^^^^^^^
here, as you can see, it is asking that 5 is equal to "5", ignoring the type, it
returns true as their value is 5 (Note that "5" is converted to 5 for checking
for == comparator) */

/*
=== operator in javascript is called the strict equals operator. It is used to
compare euals between two values, considering their types(number, string,
boolean, stc.), it is used as: */
   (5 === "5") // false
/* ^^^^^^^^^^^
here, as you can see, it is asing that 5 is equal to "5", considering the type,
it returns false as their values is same, but their type is not (Note that "5"
is not converted into 5 for checking for === comparator) */
Comment

difference between | and || in js


const a = 0;
// a || 10 --> Will result in 10, as || operator considers 0 as falsy value and resulting the right side operand
console.log(`a || 10 = ${a || 10}`);
// a ?? 10 --> Will result in 0, as ?? operator considers 0 as truthy value and resulting the left side operand
console.log(`a ?? 10 = ${a ?? 10}`);
Comment

PREVIOUS NEXT
Code Example
Javascript :: loop foreach async await 
Javascript :: javascript strin literal 
Javascript :: node 
Javascript :: json to csv 
Javascript :: how to remove an object from javascript array 
Javascript :: json_extract in non native query 
Javascript :: arrow function javascript rules 
Javascript :: node.js 
Javascript :: how to compile typescript to javascript es6 
Javascript :: javascript Arrow Function with No Argument 
Javascript :: firebase integration in react 
Javascript :: comming soon page in react 
Javascript :: get item in array from index 
Javascript :: create file object node js 
Javascript :: query selector js 
Javascript :: how to set option value in fstdropdown using ajax 
Javascript :: js chrome extension get current url 
Javascript :: .then function 
Javascript :: JavaScript for...of loop 
Javascript :: material ui sidebar without hooks 
Javascript :: vue 
Javascript :: make indexOF in js 
Javascript :: How do I use for-loops js 
Javascript :: array filter with multiple conditions 
Javascript :: Javascript first example 
Javascript :: js array modify element 
Javascript :: html form action javascript method 
Javascript :: working with multiple db in single query mongodb 
Javascript :: fs.readfilesync withFileTypes true 
Javascript :: update column with find sequelize 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =