Frequently Asked Questions on JavaScript

1. What is JavaScript?
JavaScript is prototype-based scripting language.

2. Who developed JavaScript?
Netscape Communications Corporation, Mozilla Foundation.

3. When was it developed?
In 1995

4. Who is the Father of JavaScript?
Brendan Eich

5. Syntax of JavaScript within the HTML Document.
<script type="text/javascript">
..........
</script>

6. Syntax to include an External JavaScript file in the HTML Document.
<script type="text/javascript" src="filename"></script>

7. How to declare comments in JavaScript?
Single line comment followed by '//' and Block of comments placed between '/*' and '*/'.

8. How to display text and values in the browser?
Using document.write()

9. What are the types of popup boxes?
Alert, Confirm and Prompt.

10. What is DOM?
Document Object Model (DOM) is an application programming interface (API).

11. What is the use of DOM?
DOM is used to access logical structure of the HTML document.

12. What are the tasks we can do with DOM?
Using DOM we can access, modify, change CSS styles, create Elements and Text nodes, delete Elements.

13. What is the use of document.getElementById()?
We can access Element in the document.

14. How to change content of HTML element?
Using 'innerHTML' property we can change the content of Element.
Example:
document.getElementById("element_id_name").innerHTML = "New text";

15. How to modify attribute value of HTML element?
By adding attribute to 'document.getElementById()'.
Example:
document.getElementById("element_id_name").align = "center";

16. How to change CSS style of HTML element?
By adding style.propertyname to 'document.getElementById()'.
Example:
document.getElementById("element_id_name").style.backgroundColor = "orange";

17. List few DOM events.

  • onClick
  • onChange
  • onFocus
  • onBlur
  • onSubmit
  • onLoad
  • onMouseOver
  • onMouseOut

18. How to create HTML Element?
By using 'document.createElement()'.

19. How to create Text node?
By using 'document.createTextNode()'.

20. How to append child node to parent node?
By using 'appendChild()'.

21. How to remove child node from parent node?
By using 'removeChild()'.

22. What is Node?
In Document Object Model, every element is called as Node.

23. List built-in Objects in JavaScript?

  • Number
  • String
  • Math
  • Date
  • Array
  • window
  • document
  • location
  • history
  • screen

24. How to get available width and height of Browser window?
By using 'window.innerWidth' and 'window.innerHeight'.

25. How to go back in History?
By using 'history.back()'.

26. How to go forward in History?
By using 'history.forward()'.

27. How to redirect in JavaScript?
By using 'location.href'.

28. Regular Expression for Alphabets
/^[a-zA-Z]+$/

29. Regular Expression for Numbers
/^[0-9]+$/

30. Regular Expression for Alphanumeric
/^[a-zA-Z0-9]+$/

Father of JavaScript


Brendan Eich

Brendan Eich

Born: 1961, Pennsylvania