0% found this document useful (0 votes)
49 views

11CA 14 Introduction To JavaScript v2

Uploaded by

kms195kds2007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

11CA 14 Introduction To JavaScript v2

Uploaded by

kms195kds2007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

11 Computer Applications

Chapter 14 : Introduction to JavaScript


Part-I
Choose the correct answer:
1) Which provide a common scripting language to web developers to design, test and
deploy Internet Application?
A) C B) C++ C) Java D) JavaScript
2) Expand CGI
A) Common Gateway Interface B) Complex Gateway Information
C) Common Gateway Information D) Complex Gateway Interface
3) JavaScript programming language is used to develop the
A) Dynamic Web Page B) Window C) Web Page D) Home Page
4) The Dynamic Web Page help to save server’s
A) Work B) Route C) Traffic D) Pvath
5) User entered data, is validated before sending it to server is called
A) Server traffic B) Dynamic Web Page
C) Server Route D) Web server
6) Java Scripts can be implemented using which statements?
A) <head> B) <Java> C) <script> D) <text>
7) Expand
A) Distance Hyper Text Markup language B) Dynamic Hyper Text Markup language
C) Distance High Text Markup language D) Dynamic High Text Markup language
8) How many attributes are specified for <script> tag in the scripting language?
A) 2 B) 3 C) 4 D) 5
9) Which attribute is used to indicate the scripting language and its value should be sent to
“ Text/JavaScript”
A) Language B) Text1 C) Type D) Body
10) The file reload into the browser use the shortcut key is
A) F2 B) F3 C) F4 D) F5
11) JavaScript ignores spaces that appear between
A) Command B) Scripts C) Tokens D) Text
12) A Data value for variable that appears directly in a program by using a
A) loop B) Literal C) Statement D) Text
13) Which is mostly used to give a warning message to users?
A) Alert Dialog Box B) Confirm box C) Prompt box D) Display box

11CA / Chapter 14 / Page 1 of 7


14) In the below snippet, value of x is var x = 250 + 2 – 200;
A) 50 B) 52 C) 48 D) 42

Part – II
Very Short Answers
1) Write a syntax of <script> tag
<script language="javascript" type="text/javascript">
JavaScript code
</script>

2) What is scope of variables and types of scope variable?


The scope of a variable is the life time of a variable of source code in which it is defined.
 Global variable can be defined everywhere in the JavaScript code. A global variable has global
scope
 Local variables declared only within the body of the function. A local variable has local scope.

3) Write a notes to type casting in JavaScript


 Type conversion is the act of converting one data type into a different data type which
 is also called as casting.
 In JavaScript there are two type of casting,
 Implicit casting and
 Explicit casting
 Implicit casting occurs automatically in JavaScript when you change the data stored in a
variable:
 Explicit cast is done using datatype in parenthesis.

4) How many Literals in JavaScript and mention its types.


 A literal is a fixed value given to a variable in source code.
 Literals are often used to initialize variables.
 Literal types are Integer, Floating point, Character, String and Boolean.

5) What is conditional operator give suitable example.


 The ?: is the conditional operator
 It requires three operands, hence it is called the ternary operator.
 The syntax is : var variablename=(condition) ? value1 : value2;
 The condition may be relational expression or logical expression.
 First condition will be evaluated, if the condition returns true then the value of the left side of
the colon is assigned[ value1] to the variable otherwise the value of the right side of the colon [
value2] will be assigned the variable.

For example, var result=(10>15) ?100 :150;


In the above example, since the condition returns false the value 150 will be assigned to
result.

11CA / Chapter 14 / Page 2 of 7


6) What are the comments in Java Script?
 Inserting comment or remark is a good practices in programming
 Comments will be ignored by JavaScript interpreter
 There are two types of comments,
 // is called as Single line comments
 /* */ is called as multi-line comment statement

7) Write note on types of Operator.


 The typeof operator is used to get the data type (returns a string) of its operand.
 The operand can be either a literal or a data structure such as a variable, a function, or an
object.
 typeof returns: boolean, function, number, string, and undefined.
Syntax
typeof operand
or
typeof(operand)

8) Write the role of variable in JavaScript.


 Variable is a memory location where a value can be stored.
 Variable is a symbolic name for a value.
 Variables are declared with the var keyword in JavaScript.
 Every variable has a name, called identifier.
 Every variable has a data type that indicates what kind of data the variable holds. The basic
data types in JavaScript are Strings, Numbers, and Booleans.

Eg : var no1,no2;

9) What is the use of prompt dialog box?


 The prompt dialog box is used to get INPUT from the user with a pop-up text box
 The user needs to fill in the text box field and then click OK.
 The prompt dialog box is displayed using a method called prompt() which takes two
parameters:
(i) a label which you want to display in the text box and
(ii) a default string to display in the text box.

 This dialog box has two buttons: OK and Cancel. If the user clicks the OK button, the prompt()
will return the entered value from the text box. If the user clicks the Cancel button, the
prompt() returns null. The Syntax of prompt dialog box is,

Prompt(“Message”,”defaultValue”);
(or)
window.prompt("sometext","defaultText");

11CA / Chapter 14 / Page 3 of 7


Part-III
Short Answers
1) What are the advantages of programming language?
 JavaScript programming language is used to develop Interactive Pages ( Dynamic Web Pages )
 User entered data in the Dynamic Web page can be validated before sending it to the server.
This saves server traffic, which means less load on your server.
 JavaScript includes such items as Textboxes, Buttons, drag-and-drop components and sliders to
give a Rich Interface to site visitors. For example Creating a New email account in any service
provider.

2) Brief the basic data types in Java Scripts.


 A string is a list of characters, and a string literal is indicated by enclosing the characters
in single or double quotes. Strings may contain a single character or multiple characters,
including whitespace and special characters such as \n (the newline).
 Numbers can be integer or floating-point numerical value and numeric literals are specified in
the natural way.
 Boolean can be any one of two values: true or false. Boolean literals are indicated by using true
or false directly in the source code.

3) Write note on string Operator.


 The + operator performs concatenation on for strings. The comparison operator”=” can also be
used on strings. Logical operators can also be used on string
Eg:
var String1 = "Java";
var String2 = "Script";
var String3=String1+String2;
The value at String3 is “Java Script”

4) Write about <script> tag


 JavaScript can be implemented using <script>... </script> tags.
 The <script> tag containing JavaScript can be placed anywhere within in the web page, but it
is normally recommended to be kept within the <head> tags
 The <script> tag alerts the browser program to start interpreting all the text between these
tags as a script command.
syntax
<script language="javascript" type="text/javascript">
JavaScript code
</script>
The <SCRIPT> tag takes two important attributes −
 Language − This attribute specifies the scripting language. Typically, its value will be
javascript. Although recent versions of HTML (EXtensible HyperText Markup Language -
XHTML, its successor) has phased out the use of this attribute is optional.
 Type − This attribute is used to indicate the scripting language and its value should be
set to "text/javascript"

11CA / Chapter 14 / Page 4 of 7


5) What are the uses of Logical Operators?
 Logical operators perform logical (boolean) operations.
 Logical operators combine or invert boolean values. Once comparisons are made, the logical
operators && (AND), || (OR) and ! (NOT) can be used to create more complex conditions.
Usage :
• For && (AND) the result is false if the first operand is false; otherwise, the result is the
Boolean value of the second operand.
• For || (OR) the result is true if the first operand is true; otherwise, the result is the Boolean
value of the second operand.
• For ! (NOT) the result is true if the operand is false; otherwise, the result is true.

6) Difference between the increment and Decrement operator.


++ is the increment operator. Increment operator increase the value of the operand by 1 and and
assign it back to the same operand
- - is the decrement operator. Decrement operator decrease the value of the operand by 1 and
assign back to the same operand.
Eg.
var m=10
++m makes the current value of m as 11
var x=5
--x make the current value of x as 4

Part –IV
Explain in Detail
1) Explain about the popup dialog boxes in JavaScript.

 JavaScript Dialog boxes are also called as Popup Boxes.


 They can raise an alert, or get confirmation or get INPUT from user
 Alert box, Confirm box, and Prompt box are the three types

Alert Dialog Box:


 alert() method used to give a warning message to the users. It has only “OK” button
The syntax of alert box is
alert(“Message”);
(or) Window.alert(“Message”);
Example:
alert(“Name is compulsory entry”);
(or) window.alert(“Name is compulsory entry”);

Confirm Dialog Box:


 used to take user's consent on any option.
 It has OK and Cancel buttons
 OK button – TRUE, Cancel button - FALSE

11CA / Chapter 14 / Page 5 of 7


The syntax of confirm dialog box is
confirm(“message”);
(or)
window.confirm(“message”);
Example:
confirm(“Hai Do you want to continue:”);
(or)
window.confirm(“Hai Do you want to continue:”);

Prompt Dialog Box:


 The prompt dialog box is used to get INPUT values with a pop-up text message.
 The prompt dialog box is displayed using a method called prompt() which takes two
parameters:
(i) a label which you want to display in the text box and
(ii) a default string to display in the text box.
This dialog box has two buttons: OK and Cancel. If the user clicks the OK button, the prompt() will
return the entered value from the text box. If the user clicks the Cancel button, the prompt()
returns null.
 The Syntax of prompt dialog box is,
Prompt(“Message”,”defaultValue”);
(or)
window.prompt("sometext","defaultText");
Example:
prompt(“Enter Your Name:”,”Name”);
(or)
window.prompt(“Enter Your Name:”,”Name”);

2) Explain about the Arithmetic operator with suitable example.


JavaScript supports all the basic arithmetic operators like addition (+), subtraction (–),
multiplication (*), division (/), and modulus (%, also known as the remainder operator).

JavaScript supports some shorthand arithmetic operators like +=, -=, *=, /= and %= to
evaluate arithmetic calculations.

11CA / Chapter 14 / Page 6 of 7


11CA / Chapter 14 / Page 7 of 7

You might also like