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

Posted Date:-2022-02-15 04:35:33


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

Posted Date:-2022-02-15 04:07:02


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

Posted Date:-2022-02-15 04:15:47


Question:
 JavaScript Code can be called by using ___________

1.RMI

2.Triggering Event

3.Preprocessor

4.Function/Method

Posted Date:-2022-02-15 04:32:19


Question:
 JavaScript Code can be called by using ____________

1.RMI

2.Triggering Event

3.Preprocessor

4.Function/Method

Posted Date:-2022-02-15 04:14:35


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

Posted Date:-2022-02-15 04:39:01


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

Posted Date:-2022-02-15 05:09:42


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)

Posted Date:-2022-02-15 04:43:41


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

Posted Date:-2022-02-15 04:45:19


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

1.Volatile variable

2.Mutable variable

3.Immutable variable

4. Dynamic variable

Posted Date:-2022-02-15 04:33:28


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

Posted Date:-2022-02-15 04:00:34


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

Posted Date:-2022-02-15 03:30:14


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

Posted Date:-2022-02-15 03:47:37


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

Posted Date:-2022-02-15 03:33:24


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

Posted Date:-2022-02-15 04:48:00


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

Posted Date:-2022-02-15 03:44:28


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

Posted Date:-2022-02-15 03:31:13


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

Posted Date:-2022-02-15 03:46:45


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

Posted Date:-2022-02-15 02:30:50


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

Posted Date:-2022-02-15 03:22:53


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

Posted Date:-2022-02-15 02:10:04


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

1.onclick

2.onerror

3.onmessage

4.onexception

Posted Date:-2022-02-15 03:51:19


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

1.in

2.exist

3.within

4.exists

Posted Date:-2022-02-15 05:12:00


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

Posted Date:-2022-02-15 02:28:17


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

Posted Date:-2022-02-15 04:58:37


Question:
A function definition expression can be called as __________

1.Function prototype

2.Function literal

3.Function calling

4.Function declaration

Posted Date:-2022-02-15 05:04:40


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

Posted Date:-2022-02-15 04:23:44


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

1.+

2.:

3.–

4.?:

Posted Date:-2022-02-15 05:13:02


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

Posted Date:-2022-02-15 02:18:28


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

Posted Date:-2022-02-15 02:23:31


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)

Posted Date:-2022-02-15 04:46:30


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)

Posted Date:-2022-02-15 03:56:39


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)

Posted Date:-2022-02-15 05:07:50


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

Posted Date:-2022-02-15 04:12:14


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

Posted Date:-2022-02-15 04:41:12


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]

Posted Date:-2022-02-15 04:37:31


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

Posted Date:-2022-02-15 04:02:45


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

Posted Date:-2022-02-15 05:06:20


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

Posted Date:-2022-02-15 04:03:41


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

Posted Date:-2022-02-15 03:27:18


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

Posted Date:-2022-02-15 02:08:27


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

1.Primary Expression

2.Object Creation Expression

3.Invocation Expression

4.Constructor Calling Expression

Posted Date:-2022-02-15 05:10:59


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

Posted Date:-2022-02-15 03:54:10


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

Posted Date:-2022-02-15 02:20:26


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

Posted Date:-2022-02-15 02:27:15


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

Posted Date:-2022-02-15 02:31:46


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

Posted Date:-2022-02-15 04:30:08


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

Posted Date:-2022-02-15 04:28:43


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

Posted Date:-2022-02-15 02:22:06


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

Posted Date:-2022-02-15 04:27:16


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

Posted Date:-2022-02-15 04:25:38


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

Posted Date:-2022-02-15 04:24:53


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

Posted Date:-2022-02-15 02:58:51


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

Posted Date:-2022-02-15 02:25:48


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

Posted Date:-2022-02-15 04:56:22


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

Posted Date:-2022-02-15 03:52:29


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

Posted Date:-2022-02-15 04:49:45


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

Posted Date:-2022-02-15 03:25:42


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

Posted Date:-2022-02-15 03:27:48


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

Posted Date:-2022-02-15 04:57:11


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

Posted Date:-2022-02-15 03:05:19


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

Posted Date:-2022-02-15 05:03:36


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

Posted Date:-2022-02-15 03:04:04


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

Posted Date:-2022-02-15 02:57:44


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

Posted Date:-2022-02-15 04:13:27


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

Posted Date:-2022-02-15 03:06:48


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

Posted Date:-2022-02-15 04:18:25


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

1.Function/Method

2.Preprocessor

3.Triggering Event

4.RM1

Posted Date:-2022-02-15 03:02:23


Question:
Which of the following is not a framework?

1.JavaScript .NET

2.JavaScript

3.Cocoa JS

4.jQuery

Posted Date:-2022-02-15 03:50:41


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

Posted Date:-2022-02-15 03:55:10


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

1.Null type

2. Undefined type

3.Number type

4.All of the mentioned

Posted Date:-2022-02-15 02:29:45


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

Posted Date:-2022-02-15 03:45:52


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

Posted Date:-2022-02-15 02:56:35


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

1.Sequential

2.Segmental

3.Lexical

4.Literal

Posted Date:-2022-02-15 03:28:55


Question:
Why JavaScript Engine is needed?

1. Both Compiling & Interpreting the JavaScript

2.Parsing the javascript

3.Interpreting the JavaScript

4.Compiling the JavaScript

Posted Date:-2022-02-15 03:32:23


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
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website 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!