Question : compareTo() - JavaScript example needed

Hi,

I want to override compareTo() default function in JavaScript. Can you please provide me an example on how to do that and how to utilize that ?

Thanks

Answer : compareTo() - JavaScript example needed

if ("this is string1".compareTo("this is string2")) { alert( 'they are the same')}

if (string1Var.compareTo(string2Var)) { alert( 'they are  the same')}

if (string1Var.compareTo(string2Var) ==-1) { alert( 'they are  not the  same')}


if (string1Var.compareTo(string2Var) ==false) { alert( 'string2Var is not a string')}

try {
 if (string1Var.compareTo("Some test string") ==false) { alert(  'string2Var is not a string')}
}
catch(e) {
 alert('string1Var is not a string since only strings now have compareTo when you change their prototype')
}

Random Solutions  
 
programming4us programming4us