Basic Flashcards
How does a concatenation look like?
val = firstName + ‘ ‘ + lastName;
How can you return ‘Brad Lois’ by append?
val = ‘Brad ‘
val += ‘Lois’;
How does look escaping?
val = 'That\'s something you shouldn\'t have done' val = "That's something you shouldn't have done"
How can I get the length of a string?
val = firstName.length;
How does look .concat?
val = firstName.concat(‘ ‘, lastName);
How can you put a lower case or upper case to a variable?
val = firstName.toUpperCase(); val = firstName.toLowerCase();
what is indexOf() for?
and what is lastIndexOf()?
It’s to look for a certain item within a string and return the position of it as if looking for an array and returning its position.
lastIndexOf() it’s the same but it starts from the end of the string.
tip: in indexOf() and lastIndexOf() you should enter letters so it returns the position in number.
what is charAt used for?
charAt is used in order to look for a character within an argument you should enter the value as a number so it returns the letter that is in that position.
formula to get the last character using charAt?
val = firstName.charAt(firstName.length - 1)
How .substring() works?
Gives the string from position x to position x, (look reference on vs)
What is a .substring()? what it’s the formula?
a substring is a contiguous sequence of characters within a string. For instance, “the best of” is a substring of “It was the best of times”.
val = firstName.substring(0, 4);
how it’s used.slice() and how it’s different from .substring()? what it’s the formula?
It’s mostly used to pull things out of arrays, it’s very similar to substring.
the difference between slice and substring, it’s that you can put a negative number in it so it looks for it backward to frontwards.
val = tags.split(“,”);
how does .split() works? what it’s the formula?
Can split a string into an array base on the separator, the separator it’s whatever it’s within the parenthesis and it should be within a string “”.
val = str.split(" "); val = tags.split(",");
What does replace and what it’s the formula?
with this you can replace something inside the string
val = str.replace(‘Brad’, ‘Jack’);
What’s the function of .includes? what it’s the formula?
It will return true or false if the parameter within it, it’s there or not, if it’s there return true if not false.
val = str.includes(‘Hello’);