*
Previous JavaScript question answers 21-40 JavaScript question answers 61-80 Next

JavaScript Question Answers - 41-60

41. What is the method for reading and writing a file in JavaScript

In browsers, direct file access is restricted. Use the File API for reading and downloads/server APIs for writing. In Node.js, use fs.readFile() and fs.writeFile().

42. Explain how can you submit a form using JavaScript

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

43. What are undeclared and undefined variables

- Undeclared: Variables not declared with var, let, or const.
- Undefined: Variables declared but not assigned a value.

44. What is an undefined value in JavaScript

It means a variable has been declared but not assigned any value.

45. What is unshift method in JavaScript

arr.unshift() adds one or more elements to the beginning of an array and returns the new length.

46. Does JavaScript support automatic type conversion

Yes, JavaScript performs implicit type conversion (type coercion) when required.

47. Explain the working of timers in JavaScript

Timers are created using setTimeout() (executes once after delay) and setInterval() (executes repeatedly). They can be cleared with clearTimeout() and clearInterval().

48. What are global variables

Variables declared outside any function or without var/let/const become global and accessible throughout the script.

49. What boolean operators does JavaScript support?

&& (AND), || (OR), ! (NOT)

50. Which symbol is used for comments in JavaScript

- Single-line: // comment
- Multi-line: /* comment */

51. What is ‘this’ keyword in JavaScript

this refers to the current execution context (the object that owns the function being executed).

52. What is the use of typeof operator

typeof returns the type of a variable or expression. Example: typeof "hello""string".

53. What is the difference between ViewState and SessionState

- ViewState: Maintains state of a page within the client (specific to ASP.NET).
- SessionState: Maintains state across multiple pages on the server side.

54. Explain the difference between “==” and “===”

- ==: Compares values after type conversion (loose equality).
- ===: Compares both value and type (strict equality).

55. Write the code for adding new elements dynamically

Example:
var para = document.createElement("p");
para.textContent = "New Paragraph";
document.body.appendChild(para);

56. What is === operator

The === operator checks both value and type equality (strict equality).

57. Describe the properties of an anonymous function in JavaScript

- Functions without a name.
- Often assigned to variables or used as callbacks.
- Cannot be referenced by name.
- Example: var f = function(x){ return x*x; };

58. What is a prompt box

A prompt box is used to take input from the user. Example: var name = prompt("Enter your name:");

59. Which method returns the absolute value of x

Math.abs(x)

60. Which method returns the arccosine of x, in radians

Math.acos(x)

Back to Index
Previous JavaScript question answers 21-40 JavaScript question answers 61-80 Next
*
*