Page 224 - Web Applications (803) Class 12
P. 224
Example:
var teacher = {
name: "Rahul", //Property
age : 45,
displayHello: function() { //Method
document.write ("Welcome");
}
}
3. List the two advantages and disadvantages of JavaScript.
Ans. Advantages:
Simple: JavaScript is easy to understand and learn.
Speed: As JavaScript is an "interpreted" language, it is faster than other programming languages like Java
at compiling code. It speeds up program execution by removing the need for server connections to be
established.
Disadvantages:
Cannot Debug: While certain HTML editors permit debugging, their efficiency is inferior to that of C or C++
editors. Additionally, because the browser doesn't provide any errors, the developer has trouble identifying the
problem.
Customer-side Security: The JavaScript code is visible to all and can be abused by some people. These
operations can entail making anonymous use of the source code.
4. What do you understand by datatype? What are the different datatypes present in JavaScript?
Ans. In programming, a datatype is a categorization that describes the kind of value a variable can hold and the kinds
of mathematical, relational, or logical operations that can be performed on it without producing an error. There
are 2 types of datatypes in JavaScript:
Primitive datatype
Non Primitive datatype
Primitive datatypes include string, number and Boolean.
Non Primitive datatypes include objects and arrays.
5. What is an object? Explain 2 ways of declaring an object.
Ans. Consider an object in JavaScript as a list of items, each of which is a property or method that is kept as a key-value
pair in memory.
You can define and create your own objects in any of the following ways:
Using an object literal.
The following example creates a new JavaScript object with three properties:
const student = {Name : "Rashi", age : 35, Address : "Ajmer" };
Using the keyword new.
The following example creates a new JavaScript object using new Object(), and then adds 3 properties:
const student = new Object();
student.Name = "Rashi";
222 Touchpad Web Applications-XII

