Javascript String Question 2

Introduction

What is the output of the following code?

let stringA = "Hello World";
let stringB = "Hello World";
let stringC = "Yellow World";

console.log( (stringA == stringB));   /*from  www  . ja va 2s .  c om*/
console.log( (stringA == stringC));   
console.log( (stringA >= stringB));  
console.log( (stringA <= stringC));  
console.log( (stringA > stringB));   
console.log( (stringA < stringC));  

let aaa = "AAA";
let aaaa = "AAAA";
let bb = "BB";

console.log( (aaa < aaaa));  
console.log( (bb > aaaa));   


true
false
true
true
false
true
true
true

let stringA = "Hello World";
let stringB = "Hello World";
let stringC = "Yellow World";

// First we test the two similar strings
console.log( (stringA == stringB));    // true

// Now we test the alphabetically greater string with stringA
console.log( (stringA == stringC));    // false

// Now we see that >= and <= always returns true if they are equal
console.log( (stringA >= stringB));    // true

// Here are some more equivalence tests
console.log( (stringA <= stringC));    // true
console.log( (stringA > stringB));    // false
console.log( (stringA < stringC));    // true

// Now we do some basic alphabetical comparison tests
let aaa = "AAA";
let aaaa = "AAAA";
let bb = "BB";

console.log( (aaa < aaaa));    // true
console.log( (bb > aaaa));    // true



PreviousNext

Related