Cod e Character: // / (Backslash) /" '' (Double Quote) /' ' (Single Quote) /N Newline /T Tab
Cod e Character: // / (Backslash) /" '' (Double Quote) /' ' (Single Quote) /N Newline /T Tab
Cod
e Character
\\ \ (backslash)
\n newline
\t tab
A. Case-sensitive
When you compare strings, case matters. While both string use the same letters (and those letters appear in
the same order), the first letter in the first string is a capital Y while the first letter in the second string is a
lowercase y.
'Y' != 'y'
Returns: true
B. Internal Working
In Javascript, strings are compared character-by-character in alphabetical order. Each character has a
specific numeric value, coming from ASCII value of Printable characters. For example, the character 'A' has a
value 65, and 'a' has a value 97. You can notice that a lowercase letter has a higher ASCII value than the
uppercase character. If you want to know the ASCII value of a particular character, you can try running the
code below:
// Pick a string. Your string can have any number of characters.
var my_string = "a";
// Calculate the ASCII value of the first character, i.e. the character at the
position 0.
var ASCII_value = my_string.charCodeAt(0);
// Let us print
console.log(ASCII_value);
In the example above, if you wish to print ASCII values of all the characters in your string, you would have to
use Loops that we will study in later part of this course. Just for reference, here is how you can use a loop to
print the ASCII value of all characters in a string.
var my_string = "Udacity";
The ASCII values of [A-Z] fall in the range [65-90], whereas, the ASCII values of [a-z] fall in the range [97-
122]. Therefore, when we compare strings, the comparison happens character-by-character for the
ASCII values.
By combining two boolean values together with a logical operator, you create a logical expression that
returns another boolean value. Here’s a table describing the different logical operators:
&& (AND)
A B A && B
|| (OR)
A B A || B