0% found this document useful (0 votes)
71 views

Cod e Character: // / (Backslash) /" '' (Double Quote) /' ' (Single Quote) /N Newline /T Tab

Strings in JavaScript can contain text enclosed in single or double quotes. Strings can be concatenated by adding them together. When comparing strings, case matters as uppercase and lowercase letters are considered different. Internally, strings are compared character by character based on their ASCII values, with lowercase letters having higher values than uppercase. Logical operators like AND (&&), OR (||), and NOT (!) can be used to combine boolean values and return another boolean result.

Uploaded by

Ibrahim Jabbari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Cod e Character: // / (Backslash) /" '' (Double Quote) /' ' (Single Quote) /N Newline /T Tab

Strings in JavaScript can contain text enclosed in single or double quotes. Strings can be concatenated by adding them together. When comparing strings, case matters as uppercase and lowercase letters are considered different. Internally, strings are compared character by character based on their ASCII values, with lowercase letters having higher values than uppercase. Logical operators like AND (&&), OR (||), and NOT (!) can be used to combine boolean values and return another boolean result.

Uploaded by

Ibrahim Jabbari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Strings are a collection of characters enclosed inside double or single quotes.

You can use strings to


represent data like sentences, names, addresses, and more. Did you know you can even add strings
together? In JavaScript, this is called concatenating. Concatenating two strings together is actually
.!pretty simple

here’s a list of some common special characters in JavaScript.

Cod
e Character

\\ \ (backslash)

\" '' (double quote)

\' ' (single quote)

\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";

// Iterate using a Loop


for (var i = 0; i < my_string.length; i++) {
console.log(my_string.charCodeAt(i));
}

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:

Operat Meanin Exampl


or g e How it works

&& Logical value1 Returns true if both value1 and value2 e


AND && valuate to true.
value2
|| Logical value1 Returns true if either value1 or value2 (o
OR || r even both!) evaluates to true.
value2
! Logical ! Returns the opposite of value1.
NOT value1 If value1 is true, then !value1 is false.

&& (AND)
A B A && B

true true true

true false false

false true false

false false false

|| (OR)
A B A || B

true true true

true false true


A B A || B

false true true

false false false

You might also like