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’
Which method is used, what is the output?
let strSS2 = ‘ JavaScript String String ‘
console.log(strSS2.toUpperCase());
console.log(strSS2.toLowerCase());
Changing letters
toUpperCase()
JAVASCRIPT STRING STRING
.toLowerCase()
javascript string string
Which method is used, what is the output?
let strSS3 = ‘JavaScript String String’
console.log(strSS3.search(/St/));
search() the position of first matching
11
Which method is used, what is the output?
let strSS4 = ‘JavaScript String String’
console.log(strSS4.replace(‘JavaScript’, ‘JS’));
replace()
replace str whit new str
JS String String
Which method is used, what is the output?
let strSS5 = ‘JavaScript String String’
console.log(strSS5.split(‘ ‘));
console.log(strSS5.split(‘ ‘,2));
split() - to devide str into arr of strings by separator , second parameter is for return limited number of splits
[ ‘JavaScript’, ‘String’, ‘String’ ]
[ ‘JavaScript’, ‘String’ ]
Which method is used, what is the output?
let strSS6 = ‘JavaScript@mail.com’
console.log(strSS6.slice(0,strSS6.indexOf(‘@’)));
slice() - extract a string from a string
JavaScript
Which method is used, what is the output?
let strSS7 = ‘JavaScript@mail.com’
console.log(strSS7.includes(‘@’));
includes() determinate is string contains whit another string
true