JavaScript: Strings, String Methods, and String Properties

Strings

Strings are primitive values in JS that contain letters and characters. Some examples of such include:

let firstName = ‘Megan’;
let lastName = “Paffrath”;
let quotation = ‘”Man is asked to make of himself what he is supposed to be…


This content originally appeared on DEV Community and was authored by Megan Paffrath

Strings

Strings are primitive values in JS that contain letters and characters. Some examples of such include:

let firstName = 'Megan';
let lastName = "Paffrath";
let quotation = '"Man is asked to make of himself what he is supposed to become to fulfill his destiny" -Paul Tillich';
let sentence = "Let's code some fun stuff";

String Properties

String properties are the properties applied to a string, such as string length as shown below:

let whatUp = 'What Up!';
console.log(whatUp.length); // 8

String Methods

String methods are methods that we call on a string that perform an action. Some examples include:

let intro = " Hello there! ";
console.log(intro.toUpperCase()); // HELLO THERE! (note the space before and after)
console.log(intro.trim()); //HELLO THERE!(note the removal of spaces before and after)

String Methods with Arguments

These are methods that accept arguments, as shown bellow:

let whatUp = "What Up Tho!";
console.log(whatUp.indexOf('Up')); // 5
console.log(whatUp.indexOf('$')); // -1
console.log(whatUp.slice(5)); // Up Tho!
console.log(whatUp.slice(1,4)); // hat
console.log(whatUp.replace('Tho', 'Friend?')); // What Up Friend?
console.log('lol'.repeat(10)); // lollollollollollollollollollol

note: these are some notes for myself from Section 15 of The Web Developer Bootcamp. To learn more, check out the course.


This content originally appeared on DEV Community and was authored by Megan Paffrath


Print Share Comment Cite Upload Translate Updates
APA

Megan Paffrath | Sciencx (2024-08-03T02:45:26+00:00) JavaScript: Strings, String Methods, and String Properties. Retrieved from https://www.scien.cx/2024/08/03/javascript-strings-string-methods-and-string-properties/

MLA
" » JavaScript: Strings, String Methods, and String Properties." Megan Paffrath | Sciencx - Saturday August 3, 2024, https://www.scien.cx/2024/08/03/javascript-strings-string-methods-and-string-properties/
HARVARD
Megan Paffrath | Sciencx Saturday August 3, 2024 » JavaScript: Strings, String Methods, and String Properties., viewed ,<https://www.scien.cx/2024/08/03/javascript-strings-string-methods-and-string-properties/>
VANCOUVER
Megan Paffrath | Sciencx - » JavaScript: Strings, String Methods, and String Properties. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/03/javascript-strings-string-methods-and-string-properties/
CHICAGO
" » JavaScript: Strings, String Methods, and String Properties." Megan Paffrath | Sciencx - Accessed . https://www.scien.cx/2024/08/03/javascript-strings-string-methods-and-string-properties/
IEEE
" » JavaScript: Strings, String Methods, and String Properties." Megan Paffrath | Sciencx [Online]. Available: https://www.scien.cx/2024/08/03/javascript-strings-string-methods-and-string-properties/. [Accessed: ]
rf:citation
» JavaScript: Strings, String Methods, and String Properties | Megan Paffrath | Sciencx | https://www.scien.cx/2024/08/03/javascript-strings-string-methods-and-string-properties/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.