Last Updated : Jan 1, 2023
This operator will check each other with associated data type and characters case it checks if both are same then it returns true otherwise it returns false.
Here we defined div tag with id ‘res’ for appends result in webpage. In script we defined two string variables ‘str1,str2’ with two different strings then we using strict equality operator we comparing str1 with str2.
It returns Boolean value either it true or false depends on the strings if both are same then it will return true otherwise it return false we appends that this result on webpage in detail.
<!DOCTYPE html> <html> <head> <title>STRING COMPARE</title> </head> <body> <div id="res"></div> <script> const str1="Hi"; const str2="Hii"; var r=str1 === str2; console.log(str1 === str2); document.getElementById('res').innerHTML="String1 is "+str1+" and String2 is "+str2+" comparision result is "+r; </script> </body> </html>
- <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
- The<html> tag is used to indicate the beginning of HTML document.
- As above shown <head> tag is contains information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
- Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
- <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
- In html we created <div> tag with ID ‘res’ for appends the result on webpage.
- In <script> we defined two string variables namely ‘str1,str2’ with values ‘Hi,Hii’ using ‘const’ keyword.
- Using strict equality operator we comparing two strings and result of Boolean value stored on variable ‘r’.
- Then the result is appends to html div element by ‘innerHTML’ and also displayed on console. So we appended result with div tag will displayed on webpage.
- Both </body>, </html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.
When we executing this program on browser we can see the result of Boolean value ‘false’ displayed on webpage.