JS part1
JS part1
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
• It increases the speed and reduces the • Ex. PHP, ASP, Ruby
traffic across the network
• Ex. JavaScript, VBScript
JAVASCRIPT
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>
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
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 */
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?
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
Page 6 of 9
➢ Increment Operator (++) // a++ is postfix incrementation , ++a is prefix incrementation
➢ Decrement Operator (--) //a- -is postfix decrementation, --a is prefix decrementation
➢ 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.]
Ex: a=10
b="10"
document.write(a===b); // false
➢ Less than ( < ) – returns true if left operand is less than right operand
➢ Greater than ( > ) - returns false if left operand is less than right operand
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 OR (||)
It compares two relational expressions and returns a true value IF ANY OF THE
EXPRESSIONS ARE TRUE
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?
Ex:
<script>
temp=50;
result=(temp>35)? "hot" : "cold" ;
document.write (result);
</script>
OUTPUT
hot
Page 9 of 9