1.
Do functions in JavaScript necessarily return a value?
Correct Answer
C. Few functions return values by default
Explanation
In JavaScript, functions do not necessarily return a value. While it is possible for a function to return a value using the return statement, it is not mandatory. If a function does not have a return statement, it will return undefined by default. Therefore, only a few functions in JavaScript actually return values by default.
2.
Which of the following is an example of a javascript function?
Correct Answer
A. Alert()
Explanation
The correct answer is "alert()". This is an example of a JavaScript function because it is a built-in function in JavaScript that displays a dialog box with a message and an OK button. It is commonly used to show pop-up messages or notifications to the user.
3.
It is a group of reusable code which can be called anywhere in your
program.
Correct Answer
B. Functions
Explanation
Functions are a group of reusable code that can be called anywhere in a program. They allow the programmer to break down the code into smaller, manageable pieces, making it easier to read, understand, and maintain. By using functions, the programmer can avoid repetition and promote code reusability, improving the overall efficiency and organization of the program.
4.
Consider the following code snippet :var tensquared = (function(x) {return x*x;}(10));Will the given code work ?
Correct Answer
A. Yes, perfectly
Explanation
The given code will work perfectly. It defines a function called "tensquared" which takes a parameter "x" and returns the square of "x". It then immediately invokes this function with the argument 10. The result of this invocation is assigned to the variable "tensquared". Therefore, the code will successfully calculate the square of 10 and store it in the variable "tensquared".
5.
Consider the following code snippet
Correct Answer
B. 123xyz
Explanation
The correct answer is "123xyz" because it is the only value in the code snippet that is not a number or a keyword. The other options, "123", "Exception", and "NaN", are all either numeric values or reserved keywords in programming. Therefore, "123xyz" stands out as the only value that is not a number or a keyword.
6.
For the below mentioned code snippet:var o = new Object();The equivalent statement is
Correct Answer
C. Var o= new Object;
Explanation
The correct answer is "var o= new Object;". This is because the code snippet is creating a new object using the Object constructor and assigning it to the variable "o". The syntax "new Object" is used to create a new instance of an object. The other options are incorrect because they either don't create a new object or have incorrect syntax.
7.
The most common way to definea function in JavaScript is by using the________ keyword,
Correct Answer
C. Function
Explanation
The most common way to define a function in JavaScript is by using the "function" keyword. This keyword is used to declare a named or anonymous function in JavaScript. It is followed by the function name (optional) and a set of parentheses, which can contain parameters for the function. The function body is enclosed in curly braces, where the code to be executed is written. Using the "function" keyword is the standard and widely accepted method for defining functions in JavaScript.
8.
What is the output of the following snippet: <html><head><script type="text/javascript">function sayHello(){document.write ("Hello there!");}</script></head><body><p>Click the following button to call the function</p><form><input type="button" onclick="sayHello()" value="Say Hello"></form><p>Use different text in write method and then try...</p></body></html>
Correct Answer
D. When the button is clicked an output "Hello there!" will be displayed
Explanation
The given code snippet includes a JavaScript function called "sayHello()" which uses the document.write() method to display the text "Hello there!" on the webpage. When the button is clicked, the function is called and the output "Hello there!" is displayed. Therefore, the correct answer is "when the button is clicked an output 'Hello there!' will be displayed".
9.
Which of the following statement about the function is true?
Correct Answer
B. A function can take multiple parameters separated by comma.
Explanation
The correct answer is that a function can take multiple parameters separated by a comma. This means that when defining a function, you can specify multiple variables that will be used as input when the function is called. This allows for flexibility and reusability in code, as different values can be passed to the function each time it is called.
10.
The follwing syntax is used to?<script type="text/javascript"><!--var variablename = new Function(Arg1, Arg2..., "Function Body");//--></script>
Correct Answer
A. To create a function using Function() constructor
Explanation
The given syntax is used to create a function using the Function() constructor. The Function() constructor allows us to create a new function object dynamically at runtime. It takes arguments as the function parameters and the function body as a string. This syntax is commonly used when we need to create a function dynamically based on certain conditions or inputs.
11.
Consider the following code snippet :function constfuncs()
{
var funcs = [];
for(var i = 0; i < 10; i++)
funcs[i] = function() { return i; };
return funcs;
}
var funcs = constfuncs();
funcs[5]() What does the last statement return ?
Correct Answer
C. 10
Explanation
The last statement returns 10 because the variable "i" in the for loop is declared using the "var" keyword, which has function scope. This means that when the functions in the array are called, they will all reference the same variable "i" with the value of 10, which is the last value assigned to "i" in the for loop.
12.
The behaviour of the instances present of a class inside a method is defined by
Correct Answer
B. Classes
Explanation
The behavior of the instances present of a class inside a method is defined by classes. Classes contain the blueprint or definition of objects, and methods are functions or behaviors associated with those objects. Therefore, the behavior of instances of a class, including any methods they may have, is determined by the class itself.
13.
The keyword or the property that you use to refer to an object through which they were invoked is
Correct Answer
C. This
Explanation
The keyword "this" is used to refer to the object through which a method or property is invoked. It allows access to the current object's properties and methods within its own scope.
14.
JavaScript's interaction with HTML is handled through ___ that occur whenthe user or the browser manipulates a page.
Correct Answer
D. Event
Explanation
JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page. Events are actions or occurrences that happen in the browser, such as clicking a button, submitting a form, or scrolling a page. JavaScript can listen for these events and respond to them by executing code or performing certain actions. By using events, JavaScript can dynamically update the HTML content, validate user inputs, or trigger animations and effects on the webpage.
15.
This is the most frequently used event type which occurs when a user clicks theleft button of his mouse
Correct Answer
A. OnSubmit
Explanation
The correct answer is onClick. This event type is the most frequently used when a user clicks the left button of their mouse.
16.
It is is an important keyword in JavaScript which can be used as a unaryoperator that appears before its single operand, which may be of any type.
Correct Answer
B. Void
Explanation
The keyword "void" in JavaScript is used as a unary operator that appears before its single operand. It can be used with any type of operand. When "void" is used before an expression, it evaluates the expression and then returns undefined. This can be useful in certain situations, such as when you want to execute a function but do not need to use its return value.
17.
It is the capability to store related information, whether dataor methods, together in an object.
Correct Answer
A. Encapsulation
Explanation
Encapsulation refers to the concept of bundling related information, such as data and methods, together in an object. This allows for better organization and management of the code, as well as providing data protection by hiding the internal details of the object. Encapsulation helps to achieve data abstraction and modularity, making the code more maintainable and reusable.
18.
It is the capability to store one object inside another object.
Correct Answer
D. Aggregation
Explanation
Aggregation refers to the capability of storing one object inside another object. In this concept, one object is considered as the owner or container of the other object. The contained object can exist independently and can be shared among multiple containers. This allows for a flexible and modular design, where objects can be composed and combined to create more complex structures. Aggregation is often used to represent relationships between objects in object-oriented programming, where one object is composed of or contains other objects.
19.
It is the capability to write one function or method that worksin a variety of different ways.
Correct Answer
A. PolymorpHism
Explanation
Polymorphism is the correct answer because it refers to the capability of writing a function or method that can be used in different ways. In object-oriented programming, polymorphism allows objects of different classes to be treated as objects of a common superclass, enabling them to be used interchangeably. This flexibility in functionality is a key aspect of polymorphism.
20.
It is the capability of a class to rely upon another class (ornumber of classes) for some of its properties and methods.
Correct Answer
B. Inheritance
Explanation
Inheritance is the correct answer because it allows a class to inherit properties and methods from another class, also known as the parent or base class. This enables the class to rely on the parent class for certain functionalities, reducing code duplication and promoting code reuse. Inheritance establishes an "is-a" relationship between classes, where the child class is a specialized version of the parent class.
21.
The syntax for adding a property to an object is:
Correct Answer
C. ObjectName.objectProperty = propertyValue;
Explanation
The correct answer is "objectName.objectProperty = propertyValue;". This syntax is used to add a property to an object. The propertyValue is assigned directly to the object's objectProperty without using the "new" keyword or parentheses.
22.
Which of the following is an example to show how to use thewrite() method of document object to write any content on the document
Correct Answer
B. Document.write ("Hello world");
Explanation
The correct answer is "document.write ("Hello world");". This is because the write() method of the document object is used to write content directly onto the document. In this example, the content "Hello world" is being written onto the document using the document.write() method.
23.
The____ operator is used to create an instance of an object.
Correct Answer
A. New
Explanation
The "new" operator is used to create an instance of an object. It is used in object-oriented programming to allocate memory for an object and initialize its properties and methods. By using the "new" operator, we can create multiple instances of the same class, each with its own set of values and behaviors.
24.
A _______is a function that creates and initializes an object.
Correct Answer
A. Constructor
Explanation
A constructor is a special type of function that is used to create and initialize an object. It is called when an object of a class is created and it sets the initial values of the object's properties. Constructors are essential in object-oriented programming as they ensure that objects are properly initialized before they are used. In this context, a constructor is the correct answer as it fits the definition provided in the question.
25.
Which of the following syntax is an example of properly declaring function
Correct Answer
C. Book name is : Perl
Book name is : Perl
function sayHello()
26.
When the page loads, it is called an____
Correct Answer
A. Event
Explanation
When the page loads, it is called an event.
27.
Which of the following are capabilities of functions in JavaScript?
Correct Answer
C. Accept parameters
Explanation
Functions in JavaScript have the capability to accept parameters, which allows them to receive input values from the caller. This enables functions to perform specific actions or calculations based on the provided parameters. By accepting parameters, functions can be more flexible and reusable, as they can be used with different values each time they are called. Additionally, functions in JavaScript can also return a value, allowing them to produce an output that can be used by the caller or stored in a variable for further use.
28.
Inside which HTML element do we put the JavaScript?
Correct Answer
C. Script
Explanation
In HTML, we put JavaScript code inside the "script" element. This element is used to define or reference an external script file, or to embed JavaScript code directly within the HTML document. By placing the JavaScript inside the "script" element, the browser knows that it should interpret the content as JavaScript code and execute it accordingly.
29.
Using _______ statement is how you test for a specific condition.
Correct Answer
B. If
Explanation
The "If" statement is used to test for a specific condition in programming. It allows the program to execute a certain block of code only if the condition is true. This statement is commonly used in decision-making processes, where different actions need to be taken based on different conditions.
30.
How to create a Date object in JavaScript?
Correct Answer
A. DateObjectName = new Date([parameters])
Explanation
To create a Date object in JavaScript, we use the syntax "dateObjectName = new Date([parameters])". This syntax initializes a new Date object and assigns it to the variable "dateObjectName". The optional "parameters" can be used to specify the date and time for the object.
31.
Is it possible to nest functions in JavaScript?
Correct Answer
A. True
Explanation
Yes, it is possible to nest functions in JavaScript. This means that we can define a function inside another function. The inner function will have access to the variables and scope of the outer function. This allows for the creation of more modular and organized code, as well as the ability to create private variables and functions that are only accessible within the outer function.
32.
What is mean by "this" keyword in javascript?
Correct Answer
A. It refers current object
Explanation
The "this" keyword in JavaScript refers to the current object. It is commonly used within object methods to refer to the object itself. When a method is called using dot notation, the object before the dot is considered the current object and "this" can be used to access its properties and methods.
33.
What is the output of the given script?script language="javascript">function x(){document.write(2+5+"8");}</script>
Correct Answer
D. 78
Explanation
The given script defines a function called "x" that uses the document.write() method to output the result of the expression 2 + 5 + "8". In JavaScript, when a string is concatenated with a number, the number is converted to a string before concatenation. So, the expression evaluates to "7" + "8", which results in the string "78". Therefore, the output of the script is "78".
34.
Which of the following function of String object returns a string representing the specified object?
Correct Answer
C. ToString()
Explanation
The toString() function of the String object returns a string representing the specified object. This means that it converts any object into a string representation. In the given question, the other options (toLocaleUpperCase(), toUpperCase(), substring()) do not perform the same action of converting an object into a string. Hence, toString() is the correct answer.
35.
JavaScript's interaction with HTML is handled through events that occur whenthe user or the browser manipulates a page
Correct Answer
A. True
Explanation
JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page. This means that JavaScript can respond to various actions or changes happening on an HTML page, such as clicking a button, submitting a form, or loading a new document. By using event handlers and event listeners, JavaScript code can be executed in response to these events, allowing for dynamic and interactive web pages. Therefore, the statement "True" is correct as it accurately describes the way JavaScript interacts with HTML.
36.
When the page loads, it is calledan event. When the user clicks a button, that click too is an event.
Correct Answer
A. True
Explanation
The given statement is true. When a page loads, it triggers an event known as "onload" event. This event is fired when the entire webpage including its content, images, and scripts have finished loading. Similarly, when a user clicks a button, it also triggers an event called "onclick" event. These events are essential for creating interactive webpages and allow developers to perform specific actions or execute code when certain events occur.
37.
Before we use a function, we need to define it first.
Correct Answer
A. True
Explanation
This statement is true because in programming, before we can use a function, we must first define it. Defining a function involves specifying its name, parameters, and the actions it performs. Once a function is defined, we can then call or use it in our code to execute the actions specified within the function definition.
38.
A JavaScript function should always have aReturn statement.
Correct Answer
B. False
Explanation
A JavaScript function does not always have to have a return statement. A return statement is used to specify the value that should be returned by the function. However, if a return statement is not included in a function, the function will still execute its code but will not return any value. So, it is not necessary for a JavaScript function to have a return statement.
39.
The function statement is not the only way to define a new function; you can definefunction dynamically using Function()constructor along with the newoperator.
Correct Answer
A. True
Explanation
The statement is true because in JavaScript, the Function() constructor can be used to define a new function dynamically. This allows for more flexibility in creating functions, as it is not limited to the traditional function statement syntax. The new operator is used in conjunction with the Function() constructor to create the function object.
40.
Onmouseover and onmouseout is a valid event in javascript
Correct Answer
A. True
Explanation
The statement is true because onmouseover and onmouseout are valid event handlers in JavaScript. These events are triggered when the mouse pointer enters or exits an element on a webpage, allowing developers to perform specific actions or execute code in response to these events.
41.
Objects are composed of attributes
Correct Answer
A. True
Explanation
Objects are indeed composed of attributes. Attributes are the characteristics or properties that define an object. These attributes can include things like size, color, shape, and any other relevant information that describes the object. Therefore, it is correct to say that objects are composed of attributes.
42.
The syntax for adding property is:ObjectName.objectProperty = new propertyValue;
Correct Answer
B. False
Explanation
The given statement is false because the syntax for adding a property is actually: ObjectName.propertyName = propertyValue. The "objectProperty" mentioned in the statement is not a valid syntax.
43.
Methods are the functions that let the object do something or let something be done to it.
Correct Answer
A. True
Explanation
This statement is true because methods in object-oriented programming are indeed functions that allow an object to perform certain actions or operations. These methods can be used to manipulate the object's data, interact with other objects, or perform any other necessary tasks. Methods provide the behavior or functionality of an object and allow it to respond to messages or requests. Therefore, the given answer is true.
44.
A method is a function that creates and initializes an object
Correct Answer
A. True
Explanation
A method is a function that creates and initializes an object. This statement is true because methods in object-oriented programming are functions that are associated with a particular class or object. They are responsible for creating and initializing instances of that class or object. Methods can perform various actions on the object, access its attributes, and modify its state. Therefore, it is correct to say that a method is a function that creates and initializes an object.
45.
Testing
Correct Answer
A. Click here
Explanation
The correct answer is "Click here" because the question asks for a suggestion based on the given options. Since all the options are "Do not click here" except for one, the only logical choice is to select "Click here" as the answer.