INTRODUCTION TO WEB SCRIPTING
1) Write the difference between Static & Dynamic Web Sites
Page 1 of 9
2) Write the difference between programming language & scripting language
➢ Programming languages (like c, c++, java) are used for full-fledged software development whereas
scripting languages (javascript, vbscript, ruby) are used to make coding simpler and faster
➢ Scripting languages use an INTERPRETER to translate the commands whereas Programming
languages use a COMPILER
➢ Scripting languages require a host whereas programming languages are self-executable
3) Write the difference between Client-side scripting & Server-side scripting languages
Client-side scripting Server-side scripting
• Runs at the FRONT END. • Runs at the BACK END (SERVER)
• Adds interactivity • Helps to create dynamic webpages
• It reduces the load on the server, gives and responds to the client requests
validation power to the Client and is used to retrieve content from
database
• It increases the speed and reduces the • Ex. PHP, ASP, Ruby
traffic across the network
• Ex. JavaScript, VBScript
JAVASCRIPT
➢ Brendan Eich, An American programmer, CEO of brave, co-founder of Mozilla project
developed JavaScript in 1995.
➢ JavaScript was Introduced in Netscape. JS was earlier known as LIVESCRIPT
1) Write about some features of JavaScript
➢ FAST – Its 100% text so loads quickly
➢ We can embed Javascript In Html using <script> tag
➢ INTERPRETED LANGUAGE- JS code is tested line by line
➢ JS is a LOOSELY TYPED LANGUAGE- no need to declare the variable type in advance.
➢ JS is an OBJECT BASED LANGUAGE – JS is composed of objects. Each Object has its own
properties and methods
➢ JS is an EVENT DRIVEN LANGUAGE – It can respond to users’ actions. An event is an
occurrence of activity such as a button click, key press etc. Using JavaScript we can define functions
to handle events.
Page 2 of 9
2) Which are the two ways to embed JavaScript code in html using <script> tag.
INTERNAL SCRIPT EXTERNAL SCRIPT
Write JS code in html document within the Write a text file with JS code and save it with
SCRIPT BLOCK the extension .js.
Html documents can access these external
script files using src property.
<html> <html>
<body> <body>
<script> <script language="javascript" src="pgm.js">
document.write("hello 11F") </script>
</script> </body>
</body> </html>
</html>
3) What is document object in JavaScript?
document object represents the current document on the browser window.
4) Write the difference between write() and writeln()
write( ) and writeln() are bult-in functions of document objects
write (string) writeln(string)
This method displays the string (text) This method displays the string (text)
on the screen along with a line break on the screen.
writeln() is valid only when the <pre>
tag is used
Ex 1:
<script language="javascript">
document.write ("hello");
document.write ("world");
</script>
Output
helloworld
Page 3 of 9
Ex 2:
<html>
<body>
<pre>
<script language="javascript">
document.writeln ("hello");
document.write ("world");
</script>
</pre>
</body> </html>
Output
hello
world
5) Using HTML tags in javascript
<html>
<body>
<h1> MY first JS code </h1>
<script>
document.write("<b>hello 11F<b>");
document. write ("<u> is the BEST </u>");
</script>
</body> </html>
6) What are comments? Which are the two types of comments in JS
Comments are guidelines for users or programmers. Comments won’t be rendered on the
web browser.
Page 4 of 9
2 types of comments in JS are
1) Single line comment – do not exceed the length of a line. Starts with a double slash
Ex: // comment
2) Multi line comment – exceeds the length of a line and are enclosed in /* and */
Ex: /* write your
Comments here */
7) Which is the only data type in JavaScript?
JavaScript has only one data type called Variant. Variant can hold different kind of
information such as text, number, decimal etc.
8) Which are the SIX SUBTYPES OF VARIANT
1) null
null takes no value not even 0
var mark=null
2) number
Can take positive, 0 or negative numbers. Whole numbers and floating points are
allowed
Integers can be decimal, hexadecimal (0x11A02), Octal (01107)
var mark1=77;
var mark2=86.9
3) String
Contains alphanumeric data within a single or double quote
var name = "Ann ";
4) boolean
Can take true or false value
var student=false
Page 5 of 9
5) Object
An object can be identified using its properties and methods
S= new Object( );
6) undefined
Variables are not assigned with any values
var name;
9) What is a variable?
A Variable (identifier) is a named memory location used to store data.
10 20 30
a b c
10) What are the rules for Naming Variables?
➢ Can contain alphabets, numbers and underscore only
➢ Must start with an alphabet or underscore (should not start with a number)
➢ Can’t contain white spaces and should not be more than 255 characters
➢ Keywords can’t be used as identifiers
➢ Variables are case sensitive
11) What are Keywords?
KEYWORDS are reserved words which conveys a special meaning to the compiler. They can’t be
used as identifiers
Ex for keywords – var, if, switch, for, while, Array etc
12) Which are the Arithmetic/Computational Operators in JS?
➢ Addition +
➢ Subtraction (-)
➢ Multiplication (*)
➢ Division (/)
➢ Modulus (remainder operator %)
➢ Negation operator (-)
➢ String concatenation Operator (+)
Page 6 of 9
➢ Increment Operator (++) // a++ is postfix incrementation , ++a is prefix incrementation
➢ Decrement Operator (--) //a- -is postfix decrementation, --a is prefix decrementation
13) Which are the RELATIONAL/COMPARISON OPERATORS in JS
➢ Equality operator (= =)
To check whether the value of two operands are equal. If values are equal, it returns
true
Ex: a=10
b="10"
document.write(a==b); // true
[It returns true value even though a is of integer type and b is of string type. But both
a&b contains the value 10.]
➢ Equality operator to check value and type (= = =)
This operator is a stricter equality operator which checks whether the value and the
type of the operands are equal. If both value and type of the operands are equal it
returns true.
Ex: a=10
b="10"
document.write(a===b); // false
[because their values match but types don’t match]
➢ Inequality operator (!=)
It reruns true if the values of two operands are not equal
Ex: a=10, b=100;
document.write (a!=b); //true
➢ Less than ( < ) – returns true if left operand is less than right operand
➢ Greater than ( > ) - returns false if left operand is less than right operand
➢ Less than or equal to (<=)
➢ Greater than or equal to (>=)
Ex:
a=10, b=10;
name1="abin", name2="adharsh";
document.write(a<b); //false
Page 7 of 9
document.write(a<=b); //true
document.write(a>b); //false
document.write(name1<name2); //true (checks the alphabets sequentially)
14) Name the BOOLEAN/ LOGICAL OPERATORS in JS
➢ logical AND (&&)
It compares two relational expressions and returns a true value ONLY IF BOTH
THE EXPRESSIONS ARE TRUE
true&& true true
true&& false false
false && true false
false && false false
➢ logical OR (||)
It compares two relational expressions and returns a true value IF ANY OF THE
EXPRESSIONS ARE TRUE
true || true true
true || false true
false || true true
false || false false
➢ logical NOT (!)
It is a UNARY operator as it acts on a single expression and it reverses the
expression
!true false
!false true
15) SHORT HAND OPERATORS
➢ ADD BY VALUE (+=)
➢ SUBTRACT BY VALUE (-=)
➢ MULTIPLY BY VALUE (*=)
➢ DIVIDE BY VALUE (/=)
➢ MODULUS BY VALUE (%=)
Page 8 of 9
A+=5 A=A+5
A-=5 A=A-5
A*=5 A=A*5
A/=5 A=A/5
A%=5 A=A%5
16) Which are 3 types of Operators based on the number of operands they act upon?
a) UNARY OPERATOR –acts upon a single operand
Ex: Postfix operators (A++, A--)
Prefix Operators (++A, --A)
Negation Operator like –A, -B
b) BINARY OPERATOR –acts upon two operands
Ex. All arithmetic operators A+B, A-B, A*B, A/B, A%B
c) TERNARY OPERATOR- acts upon 3 operands
Ex. Conditional Operator ( ?: ) will take 3 operands. The condition, true value and
the false value
Answer= (A>B)? 10 : 20
If is A>B, the value of Answer will become 10 otherwise it will be 20
Ex:
<script>
temp=50;
result=(temp>35)? "hot" : "cold" ;
document.write (result);
</script>
OUTPUT
hot
Page 9 of 9