JavaScript Interview Questions
Q1. What is JavaScript?
JavaScript is a lightweight, interpreted programming language used both on the client-side and server-side with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages. The general-purpose core of the language has been embedded in Netscape, Internet Explorer, and other web browsers.
Q2. What are the data types supported by JavaScript?
The data types supported by JavaScript are:
- Null
- Object
- Boolean
- Undefined
- Number
- String
- Symbol
Q3. Is JavaScript a case-sensitive language?
Yes, JavaScript is a case sensitive language. This means that the language , variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
Example
<!DOCTYPE html>
<html>
<body>
<h3>Student Marks</h3>
<p id=”Example”></p>
<script>
var Marks, marks;
Marks = 79;
marks = 77;
document.getElementById(“Example”).innerHTML = Marks;
</script>
</body>
</html>
Q4 What are the features of JavaScript?
Following are the features of JavaScript
- JavaScript is a lightweight, interpreted programming language.
- It is an open and cross-platform scripting language.
- It is designed for creating network-centric applications.
- It is complementary to and integrated with Java.
Q5 How can you create an Array in JavaScript?
<script language=”javascript”>
var array = [];
var arrays = [1, 2, 3];
</script>
Q6 How can you create an object in JavaScript?
<script language=”javascript”>
var student = {
name: “Deepak”,
class : 4,
marks: 88
};
</script>
Q7. What is the use of isNaN function?
isNan is used for check number value. it returns true if the argument is not a number; otherwise, it return false.
Q8 How to break JavaScript Code into next line?
In javascript using a backslash, ‘\,’ we can break string statement
Example:
<script language=”javascript”>
document. Write (“Example line break \a in javascript,”);
</script>
Q9. What is timers in JavaScript?
Timers are used to execute a piece of code at a set time . In javascript usingsetTimeout, setInterval, and clearInterval we can do .
ThesetTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay.
setInterval(function, delay) function repeatedly executes the given function in the mentioned delay.
clearInterval(id) function instructs the timer to stop.
10. How to use comments in JavaScript?
<script language=”javascript”>
// Commnet for Single line
/*
Commnet for
Multiple
Lines
*/
</script>