*
Previous JavaScript question answers 201-220 JavaScript Home Page Next

JavaScript Question Answers - 221-240

221. Which method converts a string to uppercase letters

str.toUpperCase()

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

date.toUTCString()

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

str.trim()

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

catch (error) { ... }

225. Which keywords are used to handle exceptions

try, catch, finally, throw

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

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

227. How do you submit a form using JavaScript?

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

228. Which method returns the number of milliseconds in a date since midnight of January 1, 1970, according to UTC time

date.getTime()

229. Which method returns the primitive value of an array

arr.valueOf()

230. Which method returns the primitive value of a String object

str.valueOf()

231. Which method returns the primitive value of a number

num.valueOf()

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

date.valueOf()

233. Which statement declares a variable

var, let, or const

234. 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();

235. 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";

236. What is variable typing

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

237. 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>

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

while (condition) { ... }

239. Is JavaScript case sensitive? Give an example

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

240. Which method returns the value of a String object

str.valueOf()

Back to Index
Previous JavaScript question answers 201-220 JavaScript Home Page Next
*
*