C developers have the strcmp()
function for comparing strings. In JavaScript, you just use the less-than and greater-than operators:
var a = 'a' ; var b = 'b' ; if ( a < b ) { // true console . log ( a + ' is less than ' + b ) ; } else if ( a > b ) { console . log ( a + ' is greater than ' + b ) ; } else { console . log ( a + ' and ' + b + ' are equal.' ) ; }
If you want to change selection, open document below and click on "Move attachment"
String - JavaScript | MDN using bracket notation, attempting to delete or assign a value to these properties will not succeed. The properties involved are neither writable nor configurable. (See Object.defineProperty() for more information.)
Comparing strings
<span>C developers have the strcmp() function for comparing strings. In JavaScript, you just use the less-than and greater-than operators:
var a = 'a';
var b = 'b';
if (a < b) { // true
console.log(a + ' is less than ' + b);
} else if (a > b) {
console.log(a + ' is greater than ' + b);
} else {
console.log(a + ' and ' + b + ' are equal.');
}
A similar result can be achieved using the localeCompare() method inherited by String instances.
Distinction between string primitives and String objects
Note that JavaSc Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details