Presentation is loading. Please wait.

Presentation is loading. Please wait.

Strings Introduction to JavaScript

Similar presentations


Presentation on theme: "Strings Introduction to JavaScript"— Presentation transcript:

1 Strings Introduction to JavaScript
1/20/2020 Strings Introduction to JavaScript © Copyright 2016, Fred McClurg All Rights Reserved Introduction to JavaScript

2 String Examples What is a string?
A series of characters between double or single quotation marks. Examples: "This is a string"; // double quotes 'Also a string'; // single quotes "12"; // string not a number 'Not a string"; // mismatched (error!) "Also not string'; // mismatched (error!) strings.html

3 Quotes within Quotes What is a string?
A string containing double quotes can be quoted using single quotes. A string containing single quotes can be quoted using double quotes. Examples: // double within single quotes 'single "quoted" string'; // single within double quotes "double 'quoted' string"; quotesInQuotes.html

4 Escaping Quotes What is an escaped quote?
Single and double quotes (and other special characters) can be escaped using the backslash “\” character. Examples: // double quotes escaped "Today's word is \"perspicacious\""; // single quote escaped 'Today\'s word is "perspicacious"'; escapingQuotes.html

5 Concatenating Strings
What is string concatenation? The plus “+” symbol is used to join strings together. Examples: // long string concatenated var conCat = "God whispers to us " + "in our pleasures ... " + "but shouts in our " + "pains. -- C.S. Lewis"; console.log( conCat ); concatStr.html

6 String Type Conversion
What is string type conversion? The plus “+” symbol is also used to convert numbers to the equivalent string. Examples: var count = 0; // integer // number is converted to string var message = "Yes we have " + count + " bananas"; console.log( message ); strTypeConvert.html

7 Line Continuation What is line continuation?
A long line can span multiple lines via the backslash “\” character as the last character on the line. Examples: // spanning lines via continuation var strCont = "The remarkable thing is, \ we have a choice everyday regarding the \ attitude we will embrace for that day. \ -- Chuck Swindoll"; console.log( strCont ); lineCont.html


Download ppt "Strings Introduction to JavaScript"

Similar presentations


Ads by Google