Sie sind auf Seite 1von 6

SET 1

MCQ ROUND(15 Marks)

1 ) var obj1 = {}; var obj2 = {}; What is the value of (obj1 === obj2)
A. true
B. false
And : false

2)The loop isn’t working. What’s the problem?

var foos = [‘a’, ‘b’, ‘c’ , ‘d’, ‘e’];


var bars = [‘x’, ‘y’, ‘z’];
for (var i = 0; i < foos.length; i++)
{ var foo = foos[i];
for (var i = 0; i < bars.length; i++)
{ var bar = bars[i];
/* some code using `bar` */
}
}

A. The inner loop resets the outer for-loop, leaving it a fixed position
each time, causing an infinite loop (hint: no block scope).
B. The outer-loop finishes after the first iteration due to a “bug” that
unfortunately is part of the ECMAScript specification.
C. There is no bug. The loop will run correctly.
D. Uncaught SyntaxError.

Ans : A

3)What does the following expression return?

1 + 5 + ” bottles of milk”;

A. “15 bottles of milk”


B. “6 bottles of milk”
SET 1

C. undefined. An exception is thrown


D. “5 bottles of milk”
Ans: B

4)How do you create an object in JavaScript?


A. var obj = {};
B. function Foo() {} var obj = new Foo();
C. All of these work.
D. var obj = new Object();

Ans : C

5) What is the result of the following statement: typeof “x”;


A. “character”
B. “[object String]”
C. Throws error “ReferenceError: x is not defined”
D. “string”
E. “undefined”

Ans : C

6) Primitive types are passed by :


A. Value
B. Pointer
C. Reference
Ans : A

7)Which is not a primitive data type in JavaScript?


A. boolean
B. number
C. string
D. character
Ans : D
SET 1

8)Which of these is a correct method to create a new array?


A. var myArray = ();
B. var myArray = [];
C. var myArray = new Array[];
D. var myArray = {};
E. var myArray = array();
Ans : B

9)To what type are values converted internally when evaluating a


conditional statement?
A. positive
B. negative
C. integer
D. tinyint
E. boolean

Ans : C

10) Which of these is not a logical operator?


A. !
B. &
C. &&
D. ||

Ans : B

11) What is the value of x? var a = false; var x = a ? “A” : “B”;


A. undefined
B. true
C. “A”
D. “B”
E. False
SET 1

Ans : D

12)Which of the following asserts that the variables `A`, `B`, and `C`
have unequal values?

A. A !== B || B !== C
B. A !== B & B !== C
C. A !== B && B !== C && A !== C
D. A !== B
Ans :C

13)Which is an example of (only) an object literal in Javascript?


A. var obj = { prop1: ‘property 1’, prop2: ‘property 2’ };
B. var obj = [ “property 1”, “property 2” ]
C. var obj = [ {prop1: ‘property 1’, prop2: ‘property2’} ]
D. var obj = new Object() { this.prop1 = ‘property 1’; this.prop2 =
‘property 2′; }

Ans: C

14)Consider: var x = [‘a’, ‘b’, ‘c’]; Which line of code will remove the
first element of the array, resulting in x being equal to [‘b’, ‘c’]?
A. x.unshift(0);
B. x.pop();
C. x.splice(0);
SET 1

D. x.splice(0, 1);

Ans : B

15)What are the values of x and y after the invocation of `foo` in


following? var x = “I am global x”; var y = “I am global y”; function
foo() { var y = x = “Hello from foo”; } foo();
A. x = “I am global x”; y = “I am global y”;
B. The function throws a SyntaxError
C. x = “Hello from foo”; y = “I am global y”;
D. x = “Hello from foo”; y = “Hello from foo”;
Ans : D

CODING ROUND

1)Write a function that would allow you to do this.(20 Marks)


var addSix = createBase(6);
addSix(10); // returns 16
addSix(21); // returns 27

function createBase(a){
return a+6;
}
function addSix(a) {
var b = createBase(a);
console.log(b);
}
addSix(6);
SET 1

2)Given two strings, return true if they are anagrams of one


another (30 Marks)

Details

For example: Mary is an anagram of Army

Input : String , Output :boolean

function checkAnagram(str1, str2) {

str1 = str1.toLowerCase().split('');

let strArr1 = sort().join('').trim();

console.log(strArr1);

str2 = str2.toLowerCase().split('');

let strArr2 = sort().join('').trim();

console.log(strArr2);

if( strArr1 == strArr2) { return true} else {return false}

console.log(checkAnagram("mary","yrma"));

Das könnte Ihnen auch gefallen