JS String Flashcards
What is log?
let name = ‘John’
let message = Hello ${name}
console.log(message);
Hello John
What is log?
let str = ‘I'm a string’
console.log(str.length);
12
What is log?
let str = ‘I'm a string’
console.log(str[7]);
t
What is log?
let str = ‘I'm a string’
console.log(str[str.length-1]);
g
What is log?
let className = ‘btn’
className += ‘ btn-primary’
className += ‘ none’
console.log(className);
btn btn-primary none
What is JS string
JS string are primitive values and immutable
Litteral string delimited by ‘ quotes, double quotes “ , backticks ~
Find the length of a string
let str = ‘I'm a string’
console.log(str.length);
How to compare 2 strings?
Use <,<=, >,>=, ==
How to get value of string?
Whit methods of the string objects:
valueOf()
toString()
toLocaleString()
How to find the character of position?
console.log(str.charAt(1))
Which method is used, what is the output?
let nameN = ‘Lia’
let fullName =nameN.concat(“ “,’LiaN’)
console.log(fullName);
let arr = [‘One’, ‘Two’, ‘Three’]
console.log(‘‘.concat(arr));
Concatenation for String
Lia LiaN
One,Two,Three
Which method is used, what is the output?
let strN = ‘JavaScript String’
console.log(strN.substr(0,10));
console.log(strN.substr(11,6));
Extracting substrings whit substr() /1 - start index 2- lenght of the number of chracters for extrating
JavaScript
String
Which method is used, what is the output?
let strS = ‘JavaScript String’
console.log(strS.substring(2,6));
Extracting substrings whit substring() /1 - start index 2- end index for extrating
vaSc
Which method is used, what is the output?
let strSS = ‘JavaScript String String’
console.log(strSS.indexOf(‘St’));
console.log(strSS.indexOf(‘St’, 12));
Locating substrings whit indexOf() - is case-sensitive
1 - substring to locate first occurence 2- index at which searching in string
if searching index dont’t exist output is -1
11
18
Which method is used, what is the output?
let strSS1 = ‘ JavaScript String String ‘
console.log(strSS1.trimStart());
console.log(strSS1.trimEnd());
Removing the space whit trimStart() for start
whit trimEnd() for end
trim() remove space from end and start
‘JavaScript String String ‘
‘ JavaScript String String’