JavaScript Code

How to check if two strings are equal?


Problem Statement

given two strings, check if the two strings are equal using JavaScript

Solution

two strings are equal if they hold the same string value. to compare two strings if they are equal using JavaScript, we can use comparison equal-value and equal-type operator. the operator returns true if the two strings are equal, or false otherwise

Program

given two strings are str1 and str2. check if str1 and str2 are equal

let str1 = 'apple';
let str2 = 'apple';
if ( str1 === str2 ) {
    console.log('two strings are equal');
} else {
    console.log('two strings are not equal');
}