|JavaScript| JavaScript: Strings and More
Code_Regina
Posted on November 30, 2020
-Introducing Strings
-Indices and Length
-String Methods
-String Methods with Arguments
-String Template Literals
-Undefined and Null
Introducing Strings
Strings are another primitive type in JavaScript. They represent text, and must be wrapped in quotes.
"String of Characters"
let firstname = "Tim";
let msg = "Please do not feed the animals";
let animal = 'doggo';
let bad = "this is bad";
It is possible to use either single or double quotes.
Indices and Length
Strings are indexed meaning that each character has a corresponding number attached to it.
Chicken
C = 0
h = 1
i = 2
c = 3
k = 4
e = 5
n = 6
String Methods
Methods are built-in actions we can perform with individual strings.
Methods help us do things like searching within a string, replacing part of a string, and changing the casing of a string.
method syntax
thing.method()
msg.toUpperCase
String Methods with Arguments
let tvShow = 'catdog';
tv.Show.indexOf('cat');
tv.Show.indexOf('dog');
tv.Show.indexOf('z');
indexOf is going to give us the string index and positional number where a given argument occurs in a string.
thing.method(arg)
Some methods accept arguments that modify their behavior.
Think of them as inputs that we can pass in.
We pass these arguments inside of the parentheses.
String Template Literals
`I counted ${3 + 4} sheep`;
Template literals are strings that allow embedded expressions, which will be evaluated and then turned into a resulting string.
Back ticks ` are used for template literals not single quotes '
Undefined and Null
Null is the intentional absence of any value, must be assigned.
Undefined variables that do not have an assigned value are undefined.
Posted on November 30, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.