JavaScript/JavaScript MCQ Set 1 Sample Test,Sample questions

Question:
 A hexadecimal literal begins with __________

1.00

2.0x

3.0X

4. Both 0x and 0X


Question:
 A JavaScript program developed on a Unix Machine ________

1.will throw errors and exceptions

2. must be restricted to a Unix Machine only

3.will work perfectly well on a Windows Machine

4.will be displayed as a JavaScript text on the browser


Question:
 JavaScript can be written __________

1.directly into JS file and included into HTML

2.directly on the server page

3.directly into HTML pages

4.directly into the css file


Question:
 JavaScript Code can be called by using ___________

1.RMI

2.Triggering Event

3.Preprocessor

4.Function/Method


Question:
 JavaScript Code can be called by using ____________

1.RMI

2.Triggering Event

3.Preprocessor

4.Function/Method


Question:
 JavaScript _________ when there is an indefinite or an infinite value during an arithmetic computation.

1.Prints an exception error

2.Prints an overflow error

3.Displays “Infinity”

4.Prints the value as such


Question:
 The expression of calling (or executing) a function or method in JavaScript is called ________

1.Primary expression

2.Functional expression

3.Invocation expression

4.Property Access Expression


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

1.if(a!=null)

2.if (!a)

3.if(a!null)

4.if(a!==null)


Question:
 The statement a===b refers to _________

1.Both a and b are equal in value, type and reference address

2.Both a and b are equal in value

3. Both a and b are equal in value and type

4.There is no such statement


Question:
 The type of a variable that is volatile is _______________

1.Volatile variable

2.Mutable variable

3.Immutable variable

4. Dynamic variable


Question:
 The web development environment (JavaScript) offers which standard construct for data validation of the input entered by the user.

1.Controlled loop constructs

2.Server page access

3.Client side Event

4.Permit server-side


Question:
 What is the basic difference between JavaScript and Java?

1.Functions are considered as fields

2.Functions are values, and there is no hard distinction between methods and fields

3. Variables are specific

4.There is no difference


Question:
 What is the prototype represents in the following JavaScript code snippet?

function javascript() {};

1.Not valid

2.Prototype of a function

3.Function javascript d)

4.A custom constructor


Question:
 What will be the function of the following JavaScript program?

var scope = "js scope";
function checkscope() 
{
    var scope = "javascript scope"; 
    function f() 
    { 
         return scope; 
    }
    return f;
}

1.Returns the value in scope

2.Returns value null

3.Shows an error message

4.Returns exception


Question:
 What will be the output of the following JavaScript code?

function compare()
{
    int num=2;
    char b=2;
    if(a==b)
        return true;
    else
        return false;
}

1.true

2.false

3.runtime error

4.compilation error


Question:
 What will be the output of the following JavaScript code?

int a=0;
for(a;a<5;a++);
console.log(a);

1.4

2.5

3.0

4.Error


Question:
 What will be the output of the following JavaScript code?

var quiz=[1,2,3];  
var js=[6,7,8];  
var result=quiz.concat(js);  
document.writeln(result);

1.1, 2, 3, 6, 7, 8

2.123

3.1, 2, 3

4.Error


Question:
 What will be the result or type of error if p is not defined in the following JavaScript code snippet?

console.log(p)

1.Value not found Error

2.Reference Error

3.Null

4.Zero


Question:
 Where is Client-side JavaScript code is embedded within HTML documents?

1. A URL that uses the special javascript:code

2.A URL that uses the special javascript:protocol

3.A URL that uses the special javascript:encoding

4. A URL that uses the special javascript:stack


Question:
 Which of the following explains correctly what happens when a JavaScript program is developed on a Unix Machine?

1.will work perfectly well on a Windows Machine

2.will be displayed as JavaScript text on the browser

3.will throw errors and exceptions

4.must be restricted to a Unix Machine only


Question:
 Which of the following is correct about JavaScript?

1.JavaScript is an Object-Based language

2.JavaScript is Assembly-language

3.JavaScript is an Object-Oriented language

4.JavaScript is a High-level language


Question:
 Which of the following is the property that is triggered in response to JS errors?

1.onclick

2.onerror

3.onmessage

4.onexception


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

1.in

2.exist

3.within

4.exists


Question:
 Will the following JavaScript code work?

var js = (function(x) {return x*x;}(10));

1.Exception will be thrown

2.Memory leak

3.Error

4.Yes, perfectly


Question:
. What will be the output of the following JavaScript code?

int a=1;
if(a!=null)
    return 1;
else
    return 0;

1.0

2.1

3.runtime error

4.compiler error


Question:
A function definition expression can be called as __________

1.Function prototype

2.Function literal

3.Function calling

4.Function declaration


Question:
A proper scripting language is a __________

1.High level programming language

2.Assembly level programming language

3.Machine level programming language

4.Low level programming language


Question:
Among the following, which one is a ternary operator?

1.+

2.:

3.–

4.?:


Question:
Among the given statements, which statement defines closures in JavaScript?

1. JavaScript is a function that is enclosed with references to its inner function scope

2.JavaScript is a function that is enclosed with references to its lexical environment

3.JavaScript is a function that is enclosed with the object to its inner function scope

4.None of the mentioned


Question:
Arrays in JavaScript are defined by which of the following statements?

1. It is an ordered list of values

2.It is an ordered list of objects

3. It is an ordered list of string

4.It is an ordered list of functions


Question:
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).

1. false.toString()

2.String(false)

3.String newvariable=”false”

4.Both false.toString() and String(false)


Question:
Consider the following JavaScript statement containing regular expressions and check if the pattern matches.

var text = "testing: 1, 2, 3"; 
var pattern = /d+/g;

1.text.check(pattern)

2.pattern.test(text)

3.text==pattern

4.text.equals(pattern)


Question:
Consider the following JavaScript 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 ____________

1.text==pattern

2.text.equals(pattern)

3.text.test(pattern)

4.pattern.test(text)


Question:
JavaScript is ideal to ________

1.make computations in HTML simpler

2.minimize storage requirements on the web server

3. increase the download time for the client

4.increase the loading time of the website


Question:
The escape sequence ‘f’ stands for _________

1.Floating numbers

2.Representation of functions that returns a value

3.f is not present in JavaScript

4.Form feed


Question:
The generalised syntax for a real number representation is __________

1. [digits][.digits][(E|e)[(+|-)]digits]

2.[digits][+digits][(E|e)[(+|-)]digits]

3.[digits][(E|e)[(+|-)]digits]

4.[.digits][digits][(E|e)[(+|-)]digits]


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

1.Create linkage between client side and server side

2.Permit server side, JavaScript code, to connect to RDBMS

3.Support only non relational database

4.To interpret JavaScript code


Question:
The property of a primary expression is ____________

1.stand-alone expressions

2.basic expressions containing all necessary functions

3.contains variable references alone

4.contains only keywords


Question:
The script tag must be placed in __________

1.the head tag

2.the head or body

3.the title or head

4.after the body tag


Question:
What happens in the following JavaScript code snippet?

var js = 0;
while (js < 10) 
{
     console.log(js);
     js++;
}

1.An exception is thrown

2.The values of js are logged or stored in a particular location or storage c)

3.The value of js from 0 to 9 is displayed in the console

4.An error is displayed


Question:
What is JavaScript?

1. JavaScript is a scripting language used to make the website interactive b) e

2.JavaScript is an assembly language used to make the website interactiv

3.JavaScript is a compiled language used to make the website interactive

4.None of the mentioned


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

1.Primary Expression

2.Object Creation Expression

3.Invocation Expression

4.Constructor Calling Expression


Question:
What will be the firstname and surname of the following JavaScript program?

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

1.objects

2.property names

3.properties

4.property values


Question:
What will be the output of the following JavaScript code snippet?

<p id="demo"></p>
var txt1 = "Sanfoundry_";
var txt2 = "Javascriptmcq";
document.getElementById("demo").innerHTML = txt1 + txt2;

1.error

2.Sanfoundry_ Javascriptmcq

3.undefined

4.Sanfoundry_Javascriptmcq


Question:
What will be the output of the following JavaScript code snippet?

// JavaScript Equalto Operators
function equalto()
{
    int num=10;
    if(num===”10”)
        return true;
    else
        return false;

1.false

2.true

3.compilation error

4.runtime error


Question:
What will be the output of the following JavaScript code snippet?

int a=1;
if(a!=null) // JavaScript not equal to Operators
    return 1;
else
    return 0;

1.0

2.1

3.compiler error

4.runtime error


Question:
What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = typeof "John" 
</script>

1.integer

2.number

3.string

4.error


Question:
What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
txt1 = “ one”;
txt1 += “two”;
document.getElementById("demo").innerHTML = txt1;
</script>

1.onetwo

2.one two

3.error

4.undefined


Question:
What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
var js = 10;
js *= 5;
document.getElementById("demo").innerHTML = js;
</script>

1.10

2.50

3.5

4.Error


Question:
What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
var x = 10;
x *= 5;
document.getElementById("demo").innerHTML = x;
</script>

1.5

2.10

3.50

4.Error


Question:
What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
var x = 5;
var y = 2;
var z = x % y;
document.getElementById("demo").innerHTML = z;
</script>

1.0

2.1

3.2

4.5


Question:
What will be the output of the following JavaScript code?

<p id="demo"></p>
var txt1 = "good";
var txt2 = "day";
document.getElementById("demo").innerHTML = txt1 + txt2;

1.good day

2.goodday

3.error

4.undefined


Question:
What will be the output of the following JavaScript code?

// Javascript code snippet to compare the height
function height()
{	
    var  height = 123.56;
    var type = (height>=190) ? "tall" : "short";
    return type;
}

1. short

2.123.56

3.tall

4.190


Question:
What will be the output of the following JavaScript code?

// JavaScript Comparison Operators
function compare()
{
    int num=2;
    char b=2;
    if(a==b)
        return true;
    else
        return false;
}

1.false

2.true

3.compilation error

4.runtime error


Question:
What will be the output of the following JavaScript code?

function compare()
{
    int a=1;
    char b=1;
    if(a.tostring()===b)
        return true;
    else 
        return false;
}

1.true

2.false

3.runtime error

4.logical error


Question:
What will be the output of the following JavaScript code?

function compare()
{
    int sanfoundry=1;
    char javascript=1;
    if(sanfoundry.tostring()===javascript)
        return true;
    else 
        return false;
}

1.runtime error

2.logical error

3.true

4.false


Question:
What will be the output of the following JavaScript code?

function equalto()
{
    int num=10;
    if(num===”10”)
        return true;
    else
        return false;
}

1.true

2.false

3.runtime error

4.compilation error


Question:
What will be the output of the following JavaScript code?

function printArray(a) 
{
     var len = a.length, i = 0;
     if (len == 0)
        console.log("Empty Array");
     else 
     {
// do-while loop in javascript
         do 
         {
             console.log(a[i]);
         } while (++i < len);
     }
}

1.Prints “Empty Array”

2.Prints 0 to the length of the array

3.Prints the numbers in the array in order

4.Prints the numbers in the array in the reverse order


Question:
What will be the output of the following JavaScript code?

function range(int javascript)
{
	int a=5;
	for(int i=0;i<javascript;i++)
	{
		console.log(a);
	} 
}
range(3);

1.2

2.5

3.55

4.Error


Question:
What will be the output of the following JavaScript code?

int a==2;
int b=4;
int ans=a+b;
print(ans);

1.2

2.6

3.0

4.Error


Question:
What will be the output of the following JavaScript code?

var a=5 , b=1
var obj = { a : 10 }
// with keyword in JavaScript
with(obj)
{
      alert(b)
}

1.1

2.10

3.5

4.Error


Question:
What will be the output of the following JavaScript code?

var string1 = ”123”;
var intvalue = 123;
alert( string1 + intvalue );

1.123246

2.246

3.123123

4.Exception


Question:
What will be the output of the following JavaScript function?

<p id="demo"></p>
<script>
function javascript() 
{
// javacript abs() method
    document.getElementById("demo").innerHTML = Math.abs(-7.25);

1.-7.25

2.7.25

3.-7

4.7


Question:
What will be the output of the following JavaScript program?

function sanfoundry(javascript)
{
	return (javascript ?  “yes” :  “no”);
}
	bool ans=true;
console.log(sanfoundry(ans));

1.Compilation error

2.Runtime error

3.Yes

4.No


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

1.parse

2.a sync

3.defer

4.type


Question:
Which is a more efficient JavaScript code snippet?
Code 1 :

// for loop in javascript
for(var num=10;num>=1;num--)
{
           document.writeln(num);
}
Code 2 :

var num=10;
while(num>=1)
{
       document.writeln(num);
       num++;
}

1.Code 1

2.Code 2

3.Both Code 1 and Code 2

4.Cannot Compare


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

1.src

2.ext

3.script

4.link


Question:
Which of the following can be used to call a JavaScript Code Snippet?

1.Function/Method

2.Preprocessor

3.Triggering Event

4.RM1


Question:
Which of the following is not a framework?

1.JavaScript .NET

2.JavaScript

3.Cocoa JS

4.jQuery


Question:
Which of the following is not an error in JavaScript?

1. Missing of Bracket

2.Division by zero

3.Syntax error

4.Missing of semicolons


Question:
Which of the following is not javascript data types?

1.Null type

2. Undefined type

3.Number type

4.All of the mentioned


Question:
Which of the following methods/operation does javascript use instead of == and !=?

1.JavaScript uses equalto() b) d)

2.JavaScript uses equals() and notequals() instead

3.JavaScript uses bitwise checking

4.JavaScript uses === and !== instead


Question:
Which of the following object is the main entry point to all client-side JavaScript features and APIs?

1.Position

2.Standard

3.Location

4.Window


Question:
Which of the following scoping type does JavaScript use?

1.Sequential

2.Segmental

3.Lexical

4.Literal


Question:
Why JavaScript Engine is needed?

1. Both Compiling & Interpreting the JavaScript

2.Parsing the javascript

3.Interpreting the JavaScript

4.Compiling the JavaScript


More MCQS

  1. JavaScript MCQ Questions And Answers
  2. JavaScript MCQ Questions And Answers Set 2
  3. JavaScript MCQ Set 1
  4. JavaScript MCQ Set 2
  5. Javascript MCQ Questions Set 1
  6. Javascript Multiple Choice Questions
  7. JAVASCRIPT MCQ
Search
Olete Team
Online Exam TestTop Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on Online Exam Testwebsite is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!