*
Previous JavaScript question answers 281-300 JavaScript question answers 321-340 Next

JavaScript Question Answers - 301-320

301. Which method returns the primitive value of a Date object

date.valueOf()

302. Which statement declares a variable

var, let, or const

303. How do you create a new object in JavaScript?

- Using object literal: var obj = {};
- Using constructor: var obj = new Object();
- Using class: class MyClass {} let obj = new MyClass();

304. What is called Variable typing in JavaScript

Variable typing means a variable can hold values of different types at different times. Example:
var x = 10; x = "hello";

305. What is variable typing

It is the dynamic assignment of types to variables depending on the value assigned at runtime.

306. What is the use of Void(0)

void(0) is used to prevent the browser from refreshing or navigating when a link is clicked. Example:
<a href="javascript:void(0);">Click</a>

307. Which statement marks a block of statements to be executed while a condition is true

while (condition) { ... }

308. Is JavaScript case sensitive? Give an example

Yes, JavaScript is case sensitive. Example:
var name = "John"; and var Name = "Doe"; are two different variables.

309. Which method returns the value of a String object

str.valueOf()

310. Which method converts an array to a string, and returns the result

arr.toString()

311. Which method converts a number to a string

num.toString()

312. Which method converts a Date object to a string

date.toString()

313. Which method converts the time portion of a Date object to a string

date.toTimeString()

314. Which method converts a string to uppercase letters

str.toUpperCase()

315. Which method converts a Date object to a string, according to universal time

date.toUTCString()

316. Which method removes whitespace from both ends of a string

str.trim()

317. Which statement marks the block of statements to be executed when an error occurs in a try block, and implements error handling

catch (error) { ... }

318. Which keywords are used to handle exceptions

try, catch, finally, throw

319. Which method adds new elements to the beginning of an array, and returns the new length

arr.unshift(element1, element2, ...)

320. How do you submit a form using JavaScript?

document.forms["formName"].submit(); or document.getElementById("formId").submit();

Back to Index
Previous JavaScript question answers 281-300 JavaScript question answers 321-340 Next
*
*