Basic And Variables

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

Underscore can be used as first letter while declaring variable in JavaScript.

A. True
B. False
Answer: _________
Question 2:

Variable declared inside JavaScript Function will be called as ____________.

A. Local Variables
B. Global Variables
C. Area Variables
D. Reference Variables
Answer: _________
Question 3:

Local Variables are destroyed after execution of function.

A. True
B. False
Answer: _________
Question 4:

What are the three important manipulations done in a for loop on a loop variable?

A. Updation, Incrementation, Initialization
B. Initialization,Testing, Updation
C. Testing, Updation, Testing
D. Initialization,Testing, Incrementation
Answer: _________
Question 5:

One of the special feature of an interpreter in reference with the for loop is that

A. Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property
B. The iterations can be infinite when an interpreter is used
C. The body of the loop is executed only once
D. All of the mentioned
Answer: _________
Question 6:

What will happen if the body of a for/in loop deletes a property that has not yet been enumerated?

A. The property will be stored in a cache
B. The loop will not run
C. That property will not be enumerated
D. All of the mentioned
Answer: _________
Question 7:

What will be the step of the interpreter in a jump statement when an exception is thrown?

A. The interpreter stops its work
B. The interpreter throws another exception
C. The interpreter jumps to the nearest enclosing exception handler
D. None of the mentioned
Answer: _________
Question 8:

Among the keywords below, which one is not a statement?

A. debugger
B. with
C. if
D. use strict
Answer: _________
Question 9:

The unordered collection of properties, each of which has a name and a value is called

A. String
B. Object
C. Serialized Object
D. All of the mentioned
Answer: _________
Question 10:

A function definition expression can be called

A. Function prototype
B. Function literal
C. Function definition
D. Function declaration
Answer: _________
Question 11:

The property of a primary expression is

A. stand-alone expressions
B. basic expressions containing all necessary functions
C. contains variable references alone
D. complex expressions
Answer: _________
Question 12:

The JavaScript’s syntax calling ( or executing ) a function or method is called

A. Primary expression
B. Functional expression
C. Invocation expression
D. Property Access Expression
Answer: _________
Question 13:

What kind of an expression is “new Point(2,3)”?

A. Primary Expression
B. Object Creation Expression
C. Invocation Expression
D. Constructor Calling Expression
Answer: _________
Question 14:

Which of the operator is used to test if a particular property exists or not?

A. in
B. exist
C. within
D. exists
Answer: _________
Question 15:

Among the following, which one is a ternary operator?

A. +
B. :
C.
D. ?:
Answer: _________
Question 16:

“An expression that can legally appear on the left side of an assignment expression.” is a well known explanation for variables, properties of objects, and elements of arrays. They are called

A. Properties
B. Prototypes
C. Lvalue
D. Definition
Answer: _________
Question 17:

JavaScript is a _______________ language

A. Object-Oriented
B. High-level
C. Assembly-language
D. Object-Based
Answer: _________
Question 18:

The output for the following code snippet would most appropriately be var a = 5 , b = 1 var obj = { a : 10 } with( obj ) { alert ( b ) }

A. 10
B. Error
C. 1
D. 5
E. 10
F. Error
G. 1
H. 5
Answer: _________
Question 19:

A conditional expression is also called a

A. Alternate to if-else
B. Immediate if
C. If-then-else statement
D. None of the mentioned
Answer: _________
Question 20:

A statement block is a

A. conditional block
B. block that contains a single statement
C. Both conditional block and single statement
D. block that combines multiple statements into a single compound statement
Answer: _________
Question 21:

When an empty statement is encountered, a JavaScript interpreter

A. Ignores the statement
B. Prompts to complete the statement
C. Throws an error
D. Throws an exception
Answer: _________
Question 22:

The “var” and “function” are

A. Keywords
B. Declaration statements
C. Datatypes
D. Prototypes
Answer: _________
Question 23:

Consider the following statements switch( expression ) { statements } In the above switch syntax, the expression is compared with the case labels using which of the following operator(s) ?

A. ==
B. equals
C. equal
D. ===
Answer: _________
Question 24:

The enumeration order becomes implementation dependent and non-interoperable if :

A. If the object inherits enumerable properties
B. The object does not have the properties present in the integer array indices
C. The delete keyword is never used
D. Object.defineProperty() is not used
Answer: _________
Question 25:

JavaScript is invented by ________.

A. Helsinki, Linus
B. W3 Group
C. Brendan Eich
D. James Gosling
Answer: _________
Question 26:

JavaScript was invented at _______ Lab.

A. AT&T Bell LAb
B. Google Lab
C. Sun Microsystem
D. Netscape
Answer: _________
Question 27:

Variable can hold ________ value at a time.

A. Multiple
B. Single
C. None of these
D. Double
Answer: _________
Question 28:

We can declare ___________ at a time. Select most appropriate option.

A. One or more Variables
B. More than One Variables
C. One Variable Only
D. None of these
Answer: _________
Question 29:

Spaces,Punctuation marks are called as __________ Symbols in JavaScript.

A. Punctual
B. None of these
C. Mandetory
D. Special
Answer: _________
Question 30:

Java Script Variable should be Case ___________.

A. Non Sensitive
B. Sensitive
Answer: _________
Question 31:

Initialization of variable can be done by writing _____ operator in between variable name and operand value.

A. EQUALS
B. =
C. VALUE
D. ==
Answer: _________
Question 32:

Multiple Declarations of variables are separated by ___________ symbol.

A. Comma
B. Semicolon
C. Asterisk
D. Colon
Answer: _________
Question 33:

JavaScript Code can be called by using

A. RMI
B. Triggering Event
C. Preprocessor
D. Function/Method
E. RMI
F. Triggering Event
G. Preprocessor
H. Function/Method
Answer: _________
Question 34:

The type of a variable that is volatile is

A. Volatile variable
B. Mutable variable
C. Immutable variable
D. Dynamic variable
Answer: _________
Question 35:

A hexadecimal literal begins with

A. 00
B. 0x
C. 0X
D. Both 0x and 0X
Answer: _________
Question 36:

The generalised syntax for a real number representation is

A. [digits][.digits][(E|e)[(+|-)]digits]
B. [digits][+digits][(E|e)[(+|-)]digits]
C. [digits][(E|e)[(+|-)]digits]
D. [.digits][digits][(E|e)[(+|-)]digits]
Answer: _________
Question 37:

When there is an indefinite or an infinity value during an arithmetic value computation, javascript

A. Prints an exception error
B. Prints an overflow error
C. Displays “Infinity”
D. Prints the value as such
Answer: _________
Question 38:

Which of the following is not considered as an error in JavaScript?

A. Syntax error
B. Missing of semicolons
C. Division by zero
D. All of the mentioned
Answer: _________
Question 39:

The escape sequence ‘f’ stands for

A. Floating numbers
B. Representation of functions that returns a value
C. f is not present in JavaScript
D. Form feed
Answer: _________
Question 40:

The snippet that has to be used to check if “a” is not equal to “null” is

A. if(a!=null)
B. if (!a)
C. if(a!null)
D. if(a!==null)
Answer: _________
Question 41:

The statement a===b refers to

A. Both a and b are equal in value, type and reference address
B. Both a and b are equal in value
C. Both a and b are equal in value and type
D. There is no such statement
Answer: _________
Question 42:

Assume that we have to convert “false” that is a non-string to string. The command that we use is (without invoking the “new” operator)

A. false.toString()
B. String(false)
C. String newvariable=”false”
D. Both false.toString() and String(false)
Answer: _________
Question 43:

The development environment offers which standard construct for data validation

A. Super controlled loop constructs
B. Case sensitivity check
C. Validation constructs
D. All of the mentioned
Answer: _________
Question 44:

The main purpose of a “Live Wire” in NetScape is to

A. Create linkage between client side and server side
B. Permit server side, JavaScript code, to connect to RDBMS
C. Support only non relational database
D. To interpret JavaScript code
Answer: _________
Question 45:

The script tag must be placed in

A. head
B. head and body
C. title and head
D. all of the mentioned
Answer: _________
Question 46:

A JavaScript program developed on a Unix Machine

A. will throw errors and exceptions
B. must be restricted to a Unix Machine only
C. will work perfectly well on a Windows Machine
D. will be displayed as a JavaScript text on the browser
Answer: _________
Question 47:

JavaScript is ideal to

A. make computations in HTML simpler
B. minimize storage requirements on the web server
C. increase the download time for the client
D. none of the mentioned
Answer: _________
Question 48:

Which attribute is used to specify that the script is executed when the page has finished parsing ( only for external scripts )

A. parse
B. a sync
C. defer
D. type
Answer: _________
Question 49:

JavaScript can be written

A. directly into JS file and included into HTML
B. directly on the server page
C. directly into HTML pages
D. all of the mentioned
Answer: _________
Question 50:

Which of the following Attribute is used to include External JS code inside your HTML Document

A. src
B. ext
C. script
D. link
Answer: _________
Question 51:

A proper scripting language is a

A. High level programming language
B. Assembly level programming language
C. Machinen level programming language
D. Low level programming language
Answer: _________
Question 52:

The object has three object attributes namely

A. Class, parameters, object’s extensible flag
B. Prototype, class, objects’ parameters
C. Prototype, class, object’s extensible flag
D. Native object, Classes and Interfacces and Object’s extensible flag
Answer: _________
Question 53:

A linkage of series of prototype objects is called as :

A. prototype stack
B. prototype chain
C. prototype class
D. prototypes
Answer: _________
Question 54:

To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the

A. isPrototypeOf() method
B. equals() method
C. === operator
D. none of the mentioned
Answer: _________
Question 55:

The purpose of extensible attribute is to

A. make all of the own properties of that object nonconfigurable
B. to configure and bring a writable property
C. “lock down” objects into a known state and prevent outside tampering
D. all of the mentioned
Answer: _________
Question 56:

The basic purpose of the toLocaleString() is to

A. return a localised object representation
B. return a parsed string
C. return a local time in the string format
D. return a localized string representation of the object
Answer: _________
Question 57:

Javascript is _________ language.

A. Programming
B. Application
C. None of These
D. Scripting
Answer: _________
Question 58:

JavaScript is ______ Side Scripting Language.

A. Server
B. Browser
C. ISP
D. None of These
Answer: _________
Question 59:

JavaScript is designed for following purpose

A. To Style HTML Pages
B. To Execute Query Related to DB on Server
C. To add interactivity to HTML Pages.
D. To Perform Server Side Scripting Opertion
Answer: _________
Question 60:

JavaScript Code is written inside file having extension __________.

A. .javascript
B. .jsc
C. .jvs
D. .js
Answer: _________
Question 61:

Local Browser used for validations on the Web Pages uses __________.

A. CSS
B. JS
C. HTML
D. Java
Answer: _________
Question 62:

We can embed JS code inside HTML directly ?

A. True
B. False
Answer: _________
Question 63:

JavaScript Code can be called by using _________.

A. RMI
B. Triggering Event
C. Preprocessor
D. Function / Method
Answer: _________
Question 64:

JS code included inside head section is loaded before loading page.

A. True
B. False
Answer: _________
Question 65:

It is good to include JS code inside footer section in order to speed up the Page loading time of Webpage.

A. True
B. False
Answer: _________
Question 66:

Which attribute is used to specifies that the script is executed when the page has finished parsing (only for external scripts)

A. parse
B. async
C. defer
D. type
Answer: _________
Question 67:

Which was the first browser to support JavaScript ?

A. IE
B. Netscape
C. Mozilla Firefox
D. Google Chrome
Answer: _________
Question 68:

Consider the following code snippet : var book = { " main title ": " JavaScript " , ' sub-title ': " The Definitive Guide " , " for ": " all audiences " ,
author : { firstname : " David " ,
surname : " Flanagan " }
}

In the above snippet, firstname and surname are

A. properties
B. property values
C. property names
D. objects
Answer: _________
Question 69:

Consider the below given syntax book [ datatype ] = assignment_value

In the above syntax, the datatype within the square brackets must be

A. An integer
B. A String
C. An object
D. None of the mentioned
Answer: _________
Question 70:

Consider the following code snippet function f () {}

The above prototype represents a

A. Function f
B. A custom constructor
C. Prototype of a function
D. Not valid
Answer: _________
Question 71:

Identify the process done in the below code snippet o = { x : 1 , y :{ z :[false,null, "" ]}}

s = JSON . stringify ( o )

p = JSON . parse ( s )

A. Object Encapsulation
B. Object Serialization
C. Object Abstraction
D. Object Encoding
Answer: _________
Question 72:

Consider the following snippet code var string1 = ” 123 ”
var intvalue = 123
alert ( string1 + intvalue )
The result would be

A. 123246
B. 246
C. 123123
D. Exception
Answer: _________
Question 73:

Consider the following statements var text = "testing: 1, 2, 3"
// Sample text var pattern = /d+/ g // Matches all instances of one or more digits In order to check if the pattern matches with the string “text”, the statement is

A. text==pattern
B. text.equals(pattern)
C. text.test(pattern)
D. pattern.test(text)
Answer: _________
Question 74:

Which is a more efficient code snippet ? Code 1 : for(var num = 10
num >= 1
num -- ) { document . writeln ( num )
} Code 2 : var num = 10
while( num >= 1 ) { document . writeln ( num )
num ++
}

A. Code 1
B. Code 2
C. Both Code 1 and Code 2
D. Cannot Compare
Answer: _________
Question 75:

Consider the following statements var count = 0
while ( count < 10 ) { console . log ( count )
count ++
} In the above code snippet, what happens?

A. The values of count is logged or stored in a particular location or storage
B. The value of count from 0 to 9 is displayed in the console
C. An error is displayed
D. An exception is thrown
Answer: _________
Question 76:

Integer Variable is declared using following syntax in JavaScript.

A. int num
B. Integer num
C. var num
D. None of the above
E. int num
F. Integer num
G. var num
H. None of the above
Answer: _________
Question 77:

Consider the following code snippet function printArray ( a ) { var len = a . length, i = 0
if ( len == 0 ) console . log (" Empty Array ")
else { do { console . log ( a [ i ])
} while ( ++ i < len )
} } What does the above code result?

A. Prints the numbers in the array in order
B. Prints the numbers in the array in the reverse order
C. Prints 0 to the length of the array
D. Prints “Empty Array”
Answer: _________
Question 78:

Consider the following code snippet function tail ( o ) { for (
o . next
o = o . next )
return o
} Will the above code snippet work? If not, what will be the error?

A. No, this will throw an exception as only numerics can be used in a for loop
B. No, this will not iterate
C. Yes, this will work
D. No, this will result in a runtime error with the message “Cannot use Linked List”
Answer: _________
Question 79:

Consider the following code snippet while ( a != 0 ) { if (spam>a == 1 ) continue
else a ++
} What will be the role of the continue keyword in the above code snippet?

A. The continue keyword restarts the loop
B. The continue keyword skips the next iteration
C. The continue keyword skips the rest of the statements in that iteration
D. None of the mentioned
Answer: _________
Question 80:

Consider the following code snippet function f ( o ) { if ( o === undefined ) debugger
} What could be the task of the statement debugger?

A. It does nothing but a simple breakpoint
B. It debugs the error in that statement and restarts the statement’s execution
C. It is used as a keyword that debugs the entire program at once
D. All of the mentioned
Answer: _________

Answer Key

1: A
2: A
3: A
4: B
Solution: In a for loop, the initialization, the test, and the update are the three crucial manipulations of a loop variable.
5: A
Solution: Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property (a string value) to it.
6: C
Solution: If the body of a for/in loop deletes a property that has not yet been enumerated, that property will not be enumerated. If the body of the loop defines new properties on the object, those properties will generally not be enumerated.
7: C
Solution: When an exception is thrown in a jump statement, the interpreter jumps to the nearest enclosing exception handler, which may be in the same function or up the call stack in an invoking function.
8: D
Solution: use strict is a directive introduced in ECMAScript5. Directives are not statements because it does not include any language keywords. Also, it can appear only at the start of a script or at the start of a function body, before any real statemenst have appeared.
9: B
Solution: An object is an unordered collection of properties, each of which has a name and a value. Property names are strings, so we can say that objects map strings to values.
10: B
Solution: A function definition expression is a “function literal” in the same way that an object initializer is an “object literal.” A Function definition expression typically consists of the keyword function followed by a comma-separated list of zero or more identifiers (the parameter names) in parentheses and a block of JavaScript code (the function body) in curly braces.
11: A
Solution: The simplest expressions, known as primary expressions, are those that stand alone — they do not include any simpler expressions. Primary expressions in JavaScript are constant or literal values, certain laguage keywords, and variable references.
12: C
Solution: An invocation expression is JavaScript’s syntax for calling (or executing) a function or method) It starts with a function expression that identifies the function to be called.
13: B
Solution: An object creation expression creates a new object and invokes a function (called a constructor) to initialize the properties of that object. Object creation expressions are like invocation expressions except that they are prefixed with the keyword new.
14: A
Solution: The operator “in” tests whether a particular property exists.
15: D
Solution: A ternary operator is a conditional operator that takes three operands. In JavaScript, ?: is the ternary operator. It is used for conditional expressions. The syntax is condition ? expr1 : expr2 . Options + , : , and - are not ternary operators.
16: C
Solution: lvalue is a historical term that means “an expression that can legally appear on the left side of an assignment expression.” In JavaScript, variables, properties of objects, and elements of arrays are lvalues.
17: D
Solution: JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java or PHP, but it is an object-based language.
18: C, G
Solution: The interpreter checks obj for property b, fails and takes it from outside of with.
19: B
Solution: A conditional expression in JavaScript is also known as an immediate if or ternary operator . The correct answer is option B. Let's understand the other options: Option A, "Alternate to if-else," is not an accurate description of a conditional expression. While a conditional expression can be used as an alternative to if-else in certain cases, it is not its primary name. Option C, "If-then-else statement," is not the commonly used term for a conditional expression. It is more commonly used to refer to the traditional if-else statement structure. Option D, "None of the mentioned," is incorrect because a conditional expression does have a specific name. Therefore, option B, "Immediate if," is the correct answer as it accurately describes the conditional expression in JavaScript. It is called "immediate" because it allows for a concise way of expressing a condition and immediately returning a value based on that condition.
20: D
Solution: A statement block is a block that combines more than one statements into a single compound statement for ease.
21: A
Solution: The JavaScript interpreter takes no action when it executes an empty statement. The empty statement is occasionally useful when you want to create a loop that has an empty body.
22: B
Solution: The var and function are declaration statements—they declare or define variables and functions. These statements define identifiers (variable and function names) that can be used elsewhere in your program and assign values to those identifiers.
23: D
Solution: When a switch executes, it computes the value of expression and then looks for a case label whose expression evaluates to the same value (where sameness is determined by the === operator).
24: A
25: C
26: D
27: B
28: A
29: D
30: B
31: B
32: A
33: D, H
Solution: JavaScript code is as easy to be implemented and run. It can be called by using a function or a method)
34: B
Solution: The variables whose values can be changed are called mutable variable types.
35: D
Solution: Generally, X or x denotes hexadecimal values. So, any integer literal that begins with 0X or 0x denotes a hexadecimal number.
36: A
Solution: Floating-point literals may also be represented using exponential notation: a real number followed by the letter e (or E), followed by an optional plus or minus sign, followed by an integer exponent. This notation represents the real number multiplied by 10 to the power of the exponent.
37: C
Solution: When the result of a numeric operation is larger than the largest representable number (overflow), the result is a special infinity value, which JavaScript prints as Infinity. Similarly, when a negative value becomes larger than the largest representable negative number, the result is negative infinity, printed as -Infinity. The infinite values behave as you would expect: adding, subtracting, multiplying, or dividing them by anything results in an infinite value (possibly with the sign reversed.
38: C
Solution: Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception, however: zero divided by zero does not have a welldefined value, and the result of this operation is the special not-a-number value, printed as NaN.
39: D
Solution: f is the JavaScript escape sequence that stands for Form feed (u000C).
40: D
Solution: The not-equal operator !== compares o to null and evaluates to either true or false.
41: C
Solution: a==b returns a true if a and b refer to the same objec ,so they are equal, else it returns a false.
42: D
Solution: A non-string can be converted in two ways without using a new operator. false.toString() and String(false).
43: D
Solution: All these facilities are available in JavaScript. Additionally, all development environments provide syntax to create and use memory variables, constants, and functions.
44: B
Solution: A Live Wire database driver also supports a number of non-relational databases.
45: B
Solution: If the script tag is placed after the body tag, then, it will not be evaluated at all. Also, it is always recommended and effective to use the script snippet in the <head> tag.
46: C
47: B
Solution: To minimize storage requirements, JavaScript is always a better say.
48: C
Solution: In order to load a page, the browser must parse the contents of all script tags, which adds additional time to the page load) By minimizing the amount of JavaScript needed to render the page, and deferring parsing of unneeded JavaScript until it needs to be executed, you can reduce the initial load time of your page.
49: D
Solution: JavaScript is a versatile programming language that can be written in various ways depending on the context and requirements. The correct answer is all of the mentioned options. Let's break down each option: Option A, "directly into JS file and included into HTML," refers to writing JavaScript code in a separate JS file with a .js extension and then linking that file to an HTML page using the script tag. This is a common approach to organize and reuse JavaScript code. Option B, "directly on the server page," implies writing JavaScript code within a server-side scripting language like PHP, ASP, or Node.js. In this case, the JavaScript code is processed on the server before sending the response to the client. Option C, "directly into HTML pages," involves writing JavaScript code directly within the script tags in an HTML file. This allows for inline scripting and is suitable for small-scale applications or quick prototyping. Therefore, option D, "all of the mentioned," is the correct answer as JavaScript can be written in JS files, included in HTML, written on the server page, or directly into HTML pages based on the specific requirements of the project.
50: A
Solution: A ”src” attribute could be used to add any external code into the HTML document.
51: A
52: C
Solution: Every object has three associated object attributes : 1. An object’s prototype is a reference to another object from which properties are inherited. 2. An object’s class is a string that caegorizes the type of an object. 3. An object’s extensible flag specifies whether new properties may be added to the object.
53: B
Solution: Consider an example, Date.prototype inherits properties from Object.prototype, so a Date object created by new Date() inherits properties from both Date.prototype and Object.prototype. This linked series of prototype objects is known as prototype chain.
54: A
Solution: To determine whether one object is the prototype of (or is part of the prototype chain of) another object, one should use the isPrototype() method. To find out if p is the prototype of o write p.isPrototypeOf(o).
55: C
Solution: The purpose of the extensible attribute is to be able to “lock down” objects into a known state and prevent outside tampering.
56: D
57: D
58: B
59: C
60: D
61: B
62: A
63: D
64: A
65: A
66: C
67: B
68: C
Solution: firstname and surname are the property names. The value of that particular property is itself an object. That is why these property names are unquoted.
69: B
Solution: When using square bracket notation, the expression inside the square brackets must evaluate to a sting or a value that can be converted to a string.
70: B
Solution: The above code snippet defines a custom constructor.
71: B
Solution: Object serialization is the process of converting an object’s state to a string from which it can later be restored.
72: C
73: D
Solution: The given pattern is applied on the text given in the parenthesis.
74: A
Solution: A for loop is always more efficient because it encapsules two individual statements(initialization and expression) within the braces.
75: B
76: C, G
77: A
Solution: The do/while loop is less commonly used when compared to the while loop. Here, it prints from the array in the given order.
78: C
Solution: The above code uses a for loop to traverse a linked list data structure and return the last object in the list. This will perfectly work.
79: C
Solution: Instead of exiting a loop like the break keyword, the continue keyword moves to the next iteration from the place encountered.
80: A
Solution: The debugger statement normally does nothing. If, however, a debugger program is available and is running, then an implementation may (but is not required to) perform some kind of debugging action. In practice, this statement acts like a breakpoint: execution of JavaScript code stops and you can use the debugger to print variable’s values.