Q. Which is/are the valid JavaScript method(s) to extract string parts?

  • (A) slice(start, end)
  • (B) substring(start, end)
  • (C) substr(start, length)
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above

Q. What will be the output of the following JavaScript code?

Code:
<script>
    let x = "Hello, IncludeHelp!";
    document.getElementById("test").innerHTML = x.slice(-13,-1);
</script>
  • (A) IncludeHelp!
  • (B) IncludeHelp
  • (C) ValueError
  • (D) Hello,
πŸ’¬ Discuss
βœ… Correct Answer: (B) IncludeHelp

Q. In JavaScript, the string template literals use ____ rather than the quotes ("") to define a string?

  • (A) Single quotes ('')
  • (B) Backslash with single quote (\’'\')
  • (C) Backslashes (\\)
  • (D) Back-ticks (``)
πŸ’¬ Discuss
βœ… Correct Answer: (D) Back-ticks (``)

Q. Which JavaScript method is used to get a number as a string?

  • (A) toString()
  • (B) intToString()
  • (C) parseInteger()
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (A) toString()

Q. What will be the output of the following JavaScript code?

Code:
<script>
    const myArray = ['h', 'e', 'l', 'l', 'o'];
    document.write(myArray[0]);
    document.write(myArray[1]);
</script>
  • (A) he
  • (B) undefinedh
  • (C) ValueError
  • (D) TypeError
πŸ’¬ Discuss
βœ… Correct Answer: (A) he

Q. What will be the output of the following JavaScript code?

Code:
<script>
    let cars = ['Honda', 'Hyundai'];
    cars.push('Mahindra');
    document.write(typeof cars + " " + cars);
</script>
  • (A) array Honda,Hyundai,Mahindra
  • (B) string Honda,Hyundai,Mahindra
  • (C) object Honda,Hyundai,Mahindra
  • (D) object "Honda", "Hyundai", "Mahindra"
πŸ’¬ Discuss
βœ… Correct Answer: (C) object Honda,Hyundai,Mahindra

Q. What will be the output of the following JavaScript code?

Code:
<script>
    let cars1 = ['Honda', 'Hyundai'];
    let cars2 = cars1;
    
    cars1.push('Mahinda');
    
    document.write(cars1 + "---" + cars2);
</script>
  • (A) Honda,Hyundai,Mahinda---Honda,Hyundai
  • (B) Honda,Hyundai,Mahinda---Honda,Hyundai,Mahinda
  • (C) Honda,Hyundai ---Honda,Hyundai
  • (D) [Honda,Hyundai,Mahinda]---[Honda,Hyundai,Mahinda]
πŸ’¬ Discuss
βœ… Correct Answer: (B) Honda,Hyundai,Mahinda---Honda,Hyundai,Mahinda

Q. What will be the output of the following JavaScript code?

Code:
<script>
	var values = [10, 20, 30, 40];
	
	var result = values.reduceRight(function(x,y){
		return (x + y);
	});
	
	document.write("Result: " + result);
</script>
  • (A) Result: 40
  • (B) Result: 70
  • (C) Result: 90
  • (D) Result: 100
πŸ’¬ Discuss
βœ… Correct Answer: (D) Result: 100

Q. What will be the output of the following JavaScript code?

Code:
<script>
	var cars = ["Honda","Hyundai","Mahindra"];
	
	var result = cars.shift();
	
	document.writeln("Result: ", cars);
</script>
  • (A) Result: Honda,Hyundai,Mahindra
  • (B) Result: Honda
  • (C) Result: Hyundai,Mahindra
  • (D) Result: Honda,Mahindra
πŸ’¬ Discuss
βœ… Correct Answer: (C) Result: Hyundai,Mahindra

Q. What will be the output of the following JavaScript code?

Code:
<script>
	var cars = ["Honda","Hyundai","Mahindra"];

	var result = cars.unshift("Toyota", "Tata");

	document.writeln("[", result, "] ", cars);
</script>
  • (A) [5] Toyota,Tata,Honda,Hyundai,Mahindra
  • (B) [5]Honda,Hyundai,Mahindra,Toyota,Tata
  • (C) [2] Toyota,Tata
  • (D) [5] Honda,Hyundai,Toyota,Tata,Mahindra
πŸ’¬ Discuss
βœ… Correct Answer: (A) [5] Toyota,Tata,Honda,Hyundai,Mahindra