Function prototype
Function literal
Function calling
Function declaration
B. Function literal
for(var num=10;num>=1;num--)
{
document.writeln(num);
}
var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}
Code 1
Code 2
Both Code 1 and Code 2
Cannot Compare
var a = [];
a.unshift(1);
a.unshift(22);
a.shift();
a.unshift(3,[4,5]);
a.shift();
a.shift();
a.shift();
1
[4,5]
[3,4,5]
Exception is thrown
var c = counter(), d = counter();
c.count()
d.count()
c.reset()
c.count()
d.count()
1
0
Null
Undefined
If the object inherits enumerable properties
The object does not have the properties present in the integer array indices
The delete keyword is never used
Object.defineProperty() is not used
var a=5 , b=1
var obj = { a : 10 }
with(obj)
{
alert(b)
}
10
Error
1
5
function f() {};
Function f
A custom constructor
Prototype of a function
Not valid
var grade='A';
var result;
switch(grade)
{
case 'A':
result+=10;
case 'B':
result+= 9;
case 'C':
result+= 8;
default:
result+= 0;
}
document.write(result);
10
27
8
0
It is mandatory
Not necessary
Few functions return values by default
some functions do not return any value
Floating numbers
Representation of functions that returns a value
is not present in JavaScript
Form feed
var grade='E';
var result;
switch(grade)
{
case 'A':
result+=10;
case 'B':
result+= 9;
case 'C':
result+= 8;
default:
result+= 0;
}
document.write(result);
10
0
18
17
The interpreter stops its work
The interpreter throws another exception
The interpreter jumps to the nearest enclosing exception handler
The interpreter throws an error
Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property
The iterations can be infinite when an interpreter is used
The body of the loop is executed only once
the iteration is finite when an interpreter is used
var grade='E';
var result;
switch(grade)
{
case 'A':
result+=10;
case 'B':
result+= 9;
case 'C':
result+= 8;
default:
result+= 0;
}
document.write(result);
10
0
18
17
const obj = {prop: 12};
Object.preventExtensions(obj);
console.log( Object.isExtensible(obj));
12
false
true
error
var val1=[1,2,3];
var val2=[6,7,8];
var result=val1.concat(val2);
document.writeln(result);
1, 2, 3
Error
1, 2, 3, 6, 7, 8
123
function compare()
{
int a=1;
char b=1;
if(a.tostring()===b)
return true;
else
return false;
}
true
false
runtime error
logical error
Int a=1;
if(a>10)
{
document.write(10);
}
else
{
document.write(a);
}
10
0
1
Undefined
00
0x
0X
Both 0x and 0X
function range(int length)
{
int a=5;
for(int i=0;i<length;i++)
{
console.log(a);
}
}
range(3);
5
555
3
error
<script>
txt1 = “ one”;
txt1 += “two”;
document.getElementById("demo").innerHTML = txt1;
</script>
onetwo
one two
error
undefined
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}
The values of count are logged or stored in a particular location or storage
The value of count from 0 to 9 is displayed in the console
An error is displayed
An exception is thrown
function tail(o)
{
for (; o.next; o = o.next) ;
return o;
}
No, this will throw an exception as only numerics can be used in a for loop
No, this will not iterate
Yes, this will work
No, this will result in a runtime error with the message Cannot use Linked List
var grade='B';
var result;
switch(grade)
{
case 'A':
{
result+=10;
break;
}
case 'B':
{
result+= 9;
break;
}
case 'C':
{
result+= 8;
break;
}
default:
result+= 0;
}
document.write(result);
10
9
8
0
conditional block
block that contains a single statement
both conditional block and a single statement
block that combines multiple statements into a single compound statement
[digits][.digits][(E|e)[(+|-)]digits]
[digits][+digits][(E|e)[(+|-)]digits]
[digits][(E|e)[(+|-)]digits]
[.digits][digits][(E|e)[(+|-)]digits]
var grade='A';
var result;
switch(grade)
{
case 'A':
result+=10;
case 'B':
result+= 9;
case 'C':
result+= 8;
default:
result+= 0;
}
document.write(result);
10
27
8
0
var a1 = [,,,];
var a2 = new Array(3);
0 in a1
0 in a2
true false
false true
true true
false true
Class, parameters, objects extensible flag
Prototype, class, objects parameters
Prototype, class, objects extensible flag
Native object, Classes and Interfaces and Objects extensible flag
switch(expression)
{
statements
}
==
equals
equal
===
var values=[1,2,3,4]
var ans=values.slice(1);
document.writeln(ans);
1, 2, 3, 4
2, 3, 4
1, 3, 4
error