I have some javascript that I'm using in a few places to check the last 3 characters of an email address. What I don't understand is why I get different outcomes when I'm getting the substring of a set variable vs when I grab the input value.
The code below will alert with value: "com"
var email = "blah@test.com";
alert(email.toLowerCase().substr(email.length - 3, 3));
However, this code that grabs the input value alerts with a value: "om"
alert($("#email").val().toLowerCase().substr($("#email").length - 3, 3));
Can anyone explain to me why the above two lines of code have different outcomes?
Here is a JSFIDDLE