JS String Flashcards

1
Q

What is log?
let name = ‘John’
let message = Hello ${name}
console.log(message);

A

Hello John

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is log?
let str = ‘I'm a string’
console.log(str.length);

A

12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is log?
let str = ‘I'm a string’
console.log(str[7]);

A

t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is log?
let str = ‘I'm a string’
console.log(str[str.length-1]);

A

g

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is log?
let className = ‘btn’
className += ‘ btn-primary’
className += ‘ none’
console.log(className);

A

btn btn-primary none

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is JS string

A

JS string are primitive values and immutable
Litteral string delimited by ‘ quotes, double quotes “ , backticks ~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Find the length of a string

A

let str = ‘I'm a string’
console.log(str.length);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to compare 2 strings?

A

Use <,<=, >,>=, ==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to get value of string?

A

Whit methods of the string objects:
valueOf()
toString()
toLocaleString()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to find the character of position?

A

console.log(str.charAt(1))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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));

A

Concatenation for String
Lia LiaN

One,Two,Three

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which method is used, what is the output?

let strN = ‘JavaScript String’
console.log(strN.substr(0,10));
console.log(strN.substr(11,6));

A

Extracting substrings whit substr() /1 - start index 2- lenght of the number of chracters for extrating

JavaScript
String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which method is used, what is the output?
let strS = ‘JavaScript String’
console.log(strS.substring(2,6));

A

Extracting substrings whit substring() /1 - start index 2- end index for extrating
vaSc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which method is used, what is the output?
let strSS = ‘JavaScript String String’
console.log(strSS.indexOf(‘St’));
console.log(strSS.indexOf(‘St’, 12));

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which method is used, what is the output?
let strSS1 = ‘ JavaScript String String ‘
console.log(strSS1.trimStart());
console.log(strSS1.trimEnd());

A

Removing the space whit trimStart() for start
whit trimEnd() for end
trim() remove space from end and start
‘JavaScript String String ‘
‘ JavaScript String String’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which method is used, what is the output?

let strSS2 = ‘ JavaScript String String ‘
console.log(strSS2.toUpperCase());
console.log(strSS2.toLowerCase());

A

Changing letters
toUpperCase()
JAVASCRIPT STRING STRING
.toLowerCase()
javascript string string

17
Q

Which method is used, what is the output?
let strSS3 = ‘JavaScript String String’
console.log(strSS3.search(/St/));

A

search() the position of first matching
11

18
Q

Which method is used, what is the output?
let strSS4 = ‘JavaScript String String’
console.log(strSS4.replace(‘JavaScript’, ‘JS’));

A

replace()
replace str whit new str
JS String String

19
Q

Which method is used, what is the output?

let strSS5 = ‘JavaScript String String’
console.log(strSS5.split(‘ ‘));
console.log(strSS5.split(‘ ‘,2));

A

split() - to devide str into arr of strings by separator , second parameter is for return limited number of splits
[ ‘JavaScript’, ‘String’, ‘String’ ]
[ ‘JavaScript’, ‘String’ ]

20
Q

Which method is used, what is the output?
let strSS6 = ‘JavaScript@mail.com’
console.log(strSS6.slice(0,strSS6.indexOf(‘@’)));

A

slice() - extract a string from a string
JavaScript

21
Q

Which method is used, what is the output?

let strSS7 = ‘JavaScript@mail.com’
console.log(strSS7.includes(‘@’));

A

includes() determinate is string contains whit another string

true