Interview Questions on Java Script
41. How to write “ in string that is enclosed with in doublequotes?
Use \”
42. How to write new line in string?
Use \n
43. How to write string in multiples lines?
Use \
44. Can we compare objects?
You can compare keys of objects.
45. How to get character from particular position in string?
Use CharAt(val);
Ex :-
var str = "HELLO WORLD";
var res = str.charAt(0);
46. What is the method used for join two strings?
Conacat();
Ex :-
var str1 = "Hello ";
var str2 = "world!";
var res = str1.concat(str2);
47. What is the use of indexOf()?
Tells position of particular character or string.
Ex:-
var str = "Hello world, welcome to the universe.";
var n = str.indexOf("welcome");
48. What is the use of lastIndexOf()?
Tells position of last occurrence of particular character or string.
Ex:-
var str = "Hello world, welcome to the universe.";
var n = str.lastIndexOf("welcome");
49. How to replace part of string?
Use str.replace();
Ex :-
var str = "Visit Microsoft!";
var res = str.replace("Microsoft", "W3Schools");
50. What is the use of split()?
The split() method is used to split a string into an array of substrings, and returns the new array.
Ex :-
var str = "How are you doing today?";
var res = str.split(" ");
res contains: How,are,you,doing,today?