0% found this document useful (0 votes)
30 views39 pages

Website Dev't and PHP Question

The document is a worksheet for a website development management course focusing on PHP, containing multiple-choice questions with answers and explanations. It covers various topics related to PHP, including its definition, syntax, functions, and programming concepts. The worksheet is prepared by Gemechu A for Rift Valley University Nekemte TVET College, Department of WD$DBA.

Uploaded by

Sagni Amenu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views39 pages

Website Dev't and PHP Question

The document is a worksheet for a website development management course focusing on PHP, containing multiple-choice questions with answers and explanations. It covers various topics related to PHP, including its definition, syntax, functions, and programming concepts. The worksheet is prepared by Gemechu A for Rift Valley University Nekemte TVET College, Department of WD$DBA.

Uploaded by

Sagni Amenu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

RIFT VALLEY UNIVESITY NEKEMTE TVET COLLEGE

DEPARTMENT OF WD$DBA

WEBSITE DEV’T MGT

WORK SHEET

PREPARED BY GEMECHU A

ALL QUESTIONS ARE WITH ANSWER

ITEM OF QUESTION: ALL ARE CHOICE

1. What is PHP?

a) PHP is an open-source programming language

b) PHP is used to develop dynamic and interactive websites

c) PHP is a server-side scripting language

d) All of the mentioned

Explanation: PHP is an open-source server-side scripting language that is used to build dynamic
and interactive web pages or web applications.

2. Who is the father of PHP?

a) Drek Kolkevi

b) Rasmus Lerdorf

c) Willam Makepiece

d) List Barely

Explanation: PHP was originally created by Rasmus Lerdorf in 1994.

P R E P A R E D B Y GEMECHU . A Page 1
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

3. What does PHP stand for?

a) PHP stands for Preprocessor Home Page

b) PHP stands for Pretext Hypertext Processor

c) PHP stands for Hypertext Preprocessor

d) PHP stands for Personal Hyper Processor

Explanation: PHP previously stood for Personal Home Page now stands for “Hypertext
Preprocessor”.

4. Which of the following is the correct syntax to write a PHP code?

a) <?php ?>

b) < php >

c) < ? php ?>

d) <? ?>

Explanation: Every section of PHP code starts and ends by turning on and off PHP tags to let the
server know that it needs to execute the PHP in between them.

5. Which of the following is the correct way to add a comment in PHP code?

a) #

b) //

c) /* */

d) All of the mentioned

Explanation: In PHP, /* */ can also be used to comment just a single line although it is used for
paragraphs. // and # are used only for single-line comments.

6. Which of the following is the default file extension of PHP files?

P R E P A R E D B Y GEMECHU . A Page 2
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

a) .php

b) .ph

c) .xml

d) .html

Explanation: To run a PHP file on the server, it should be saved as AnyName.php

7. How to define a function in PHP?

a) functionName(parameters) {function body}

b) function {function body}

c) function functionName(parameters) {function body}

d) data type functionName(parameters) {function body}

Explanation: PHP allows us to create our own user-defined functions. Any name ending with an
open and closed parenthesis is a function. The keyword function is always used to begin a
function.

8. What will be the output of the following PHP code?

<?php

$x = 10;

$y = 20;

if ($x > $y && 1||1)

print "1000 PHP MCQ" ;

else

print "Welcome to Sanfoundry";

?>

P R E P A R E D B Y GEMECHU . A Page 3
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

a) no output

b) Welcome to Sanfoundry

c) 1000 PHP MCQ

d) error

Explanation: Expression evaluates to true.

Output:

1000 PHP MCQ

9. Which is the right way of declaring a variable in PHP?

a) $3hello

b) $_hello

c) $this

d) $5_Hello

Explanation: A variable in PHP can not start with a number, also $this is mainly used to refer
properties of a class so we can‟t use $this as a user defined variable name.

10. What will be the output of the following PHP program?

<?php

$fruits = array ("apple", "orange", array ("pear", "mango"),"banana");

echo (count($fruits, 1));

?>

a) 6

b) 5

P R E P A R E D B Y GEMECHU . A Page 4
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

c) 4

d) 3

Explanation: function count() will return the number of elements in an array. The parameter 1
counts the array recursively i.e it will count all the elements of multidimensional arrays.

11. What will be the output of the following PHP program?

<?php

function multi($num)

if ($num == 3)

echo "I Wonder";

if ($num == 7)

echo "Which One";

if ($num == 8)

echo "Is The";

if ($num == 19)

echo "Correct Answer";

$can = stripos("I love php, I love php too!","PHP");

multi($can);

?>

a) Correct Answer

P R E P A R E D B Y GEMECHU . A Page 5
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

b) Is The

c) I Wonder

d) Which One

Explanation: The stripos() function finds the position of the first occurrence of a string inside
another string. In this case it returns 7.

12. Which of the following PHP functions can be used for generating unique ids?

a) md5()

b) uniqueid()

c) mdid()

d) id()

Explanation: The function uniqueid() is used to generate a unique ID based on the microtime
(current time in microseconds). The ID generated from the function uniqueid() is not optimal, as
it is based on the system time. To generate an ID which is extremely difficult to predict we can
use the md5() function.

13. In the following PHP program, what is/are the properties?

<?php

class Example

public $name;

function Sample()

echo "Learn PHP @ Sanfoundry";

P R E P A R E D B Y GEMECHU . A Page 6
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

?>

a) function sample()

b) echo “This is an example”;

c) public $name;

d) class Example

Explanation: Above code is an example of „classes‟. Classes are the blueprints of objects.
Classes are the programmer-defined data type, which includes the local methods and the local
variables. Class is a collection of objects which has properties and behaviour.

14. What will be the output of the following PHP code?

<?php

define("GREETING", "PHP is a scripting language");

echo $GREETING;

?>

a) $GREETING

b) no output

c) PHP is a scripting language

d) GREETING

Explanation: Constants do not need a $ before them, they are referenced by their variable names
itself.

15. A function in PHP which starts with (double underscore) is known as

P R E P A R E D B Y GEMECHU . A Page 7
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

a) Default Function

b) User Defined Function

c) Inbuilt Function

d) Magic Function

Explanation: PHP functions that start with a double underscore – a “ ” – are called magic
functions. They are functions that are always defined inside classes, and are not stand-alone
functions.

16. How many functions does PHP offer for searching and modifying strings using Perl-
compatible regular expressions.

a) 10

b) 7

c) 8

d) 9

Explanation: The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(),


preg_quote(), preg_replace(), preg_replace_callback(), and preg_split().

17. Which of the following web servers are required to run the PHP script?

a) Apache and PHP

b) IIS

c) XAMPP

d) Any of the mentioned

Explanation: To run PHP code you need to have PHP and a web server, both IIS, XAMPP and
Apache are web servers. You can choose either one according to your platform.

18. What will be the output of the following PHP code snippet?

P R E P A R E D B Y GEMECHU . A Page 8
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

<?php

$url = "[email protected]";

echo ltrim(strstr($url, "@"),"@");

?>

a) [email protected]

b) [email protected]

c) phpmcq@

d) sanfoundry.com

Explanation: The strstr() function returns the remainder of a string beginning with the first
occurrence of a predefined string.

19. Which of the following PHP functions can be used to get the current memory usage?

a) memory_get_usage()

b) memory_get_peak_usage()

c) get_peak_usage()

d) get_usage()

Explanation: memory_get_usage() returns the amount of memory, in bytes, that‟s currently being
allocated to the PHP script. We can set the parameter „real_usage‟ to TRUE to get total memory
allocated from system, including unused pages. If it is not set or FALSE then only the used
memory is reported. To get the highest amount of memory used at any point, we can use the
memory_get_peak_usage() function.

20. Which one of the following PHP function is used to determine a file‟s last access time?

a) filetime()

b) fileatime()

P R E P A R E D B Y GEMECHU . A Page 9
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

c) fileltime()

d) filectime()

Explanation: The fileatime() function returns a file‟s last access time in Unix timestamp format
or FALSE on error.

21. What will be the output of the following PHP code?

<?php

$x = 5;

$y = 10;

function fun()

$y = $GLOBALS['x'] + $GLOBALS['y'];

fun();

echo $y;

?>

a) 5

b) 10

c) 15

d) Error

Explanation: The value of global variable y does not change therefore it‟ll print 10;

22. PHP recognizes constructors by the name

P R E P A R E D B Y GEMECHU . A Page 10
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

a) function construct()

b) function _construct()

c) classname()

d) _construct()

Explanation: PHP recognizes constructors by double underscore followed by the construct


keyword. Its syntax is function construct ([ argument1, argument2,…..]) { Class Initialization
code }.

23. The developers of PHP deprecated the safe mode feature as of which PHP version?

a) PHP 5.3.1

b) PHP 5.3.0

c) PHP 5.1.0

d) PHP 5.2.0

Explanation: This happened because safe mode often creates many problems as it resolves,
largely due to the need for enterprise applications to use many of the features safe mode disables.

24. What will be the value of the variable $input in the following PHP program?

<?php

$input = "PHP<td>stands for</td>Hypertext<i>Preprocessor</i>!";

$input = strip_tags($input,"<i></i>");

echo $input;

?>

a) PHP stands for Hypertext <i>Preprocessor</i>!

P R E P A R E D B Y GEMECHU . A Page 11
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

b) PHP stands for Hypertext Preprocessor!

c) PHP <td>stands for</td> Hypertext <i>Preprocessor</i>!

d) PHP <td>stands for</td> Hypertext Preprocessor!

Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially
wreak havoc on a page.

25. Which of the following variables does PHP use to authenticate a user?

i) $_SERVER['PHP_AUTH_USER'].

ii) $_SERVER['PHP_AUTH_USERS'].

iii) $_SERVER['PHP_AUTH_PU'].

iv) $_SERVER['PHP_AUTH_PW'].

a) ii) and iv)

b) i) and iv)

c) ii) and iii)

d) i) and ii)

Explanation: $_SERVER[„PHP_AUTH_USER‟] and $_SERVER[„PHP_AUTH_PW‟] store the


username and password values, respectively.

26. What does PDO stand for?

a) PHP Database Orientation

b) PHP Data Orientation

c) PHP Data Object

d) PHP Database Object

P R E P A R E D B Y GEMECHU . A Page 12
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

Explanation: PDO stands for PHP Data Object. The PDO class provides a common interface to
different database applications.

27. What will be the output of the following PHP program?

<?php

$a = 100;

if ($a > 10)

printf("PHP Quiz");

else if ($a > 20)

printf("PHP MCQ");

else if($a > 30)

printf("PHP Program");

?>

a)

PHP Quiz

PHP MCQ

PHP Program

b) PHP Quiz

c) No output

d) PHP MCQ

Explanation: In if else if one condition is satisfied then no other condition is checked.

28. Which of the looping statements is/are supported by PHP?

P R E P A R E D B Y GEMECHU . A Page 13
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

i) for loop

ii) while loop

iii) do-while loop

iv) foreach loop

a) Only iv)

b) i) and ii)

c) i), ii) and iii)

d) i), ii), iii) and iv)

Explanation: All are supported looping statements in PHP as they can repeat the same block of
code a given number of times, or until a certain condition is met.

29. Which PHP statement will give output as $x on the screen?

a) echo “\$x”;

b) echo “$$x”;

c) echo “/$x”;

d) echo “$x;”;

Explanation: A backslash is used so that the dollar sign is treated as a normal string character
rather than prompt PHP to treat $x as a variable. The backslash used in this manner is known as
the escape character.

30. Which version of PHP introduced the advanced concepts of OOP?

a) PHP 6

b) PHP 4

c) PHP 5

P R E P A R E D B Y GEMECHU . A Page 14
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

d) PHP 5.3

Explanation: Advanced concepts of OOP were introduced in PHP version 5.

31. What will be the output of the following PHP code?

<?php

$x = 4;

$y = 3

$z = 1;

$z = $z + $x + $y;

echo "$z";

?>

a) 15

b) 8

c) 1

d) $z

Explanation: Normal addition of variables x, y and z occurs and result of 8 will be displayed.

32. What will be the output of the following PHP program?

<?php

$a = "$winner";

$b = "/$looser";

echo $a,$b;

?>

P R E P A R E D B Y GEMECHU . A Page 15
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

a) /

b) $looser

c) /$looser

d) $winner/$looser

Explanation: Since variables $winner and $looser is not defined we only see / as output.

33. Which one of the following is the default PHP session name?

a) PHPSESSIONID

b) PHPIDSESS

c) PHPSESSID

d) PHPSESID

Explanation: PHPSESSID is the default PHP session name. You can change this name by using
the session.name directive.

34. What will be the output of the following PHP program?

<?php

$mcq = 1;

switch(print $mcq)

case 2:

print "HTML";

break;

case 1:

P R E P A R E D B Y GEMECHU . A Page 16
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

print "CSS";

break;

default:

print "JavaScript";

?>

a) error

b) 1HTML

c) 1JavaScript

d) 1CSS

Explanation: Print returns 1, thus it gives case 1.

35. What will be the output of the following PHP program?

<?php

define("VAR_NAME","test");

${VAR_NAME} = "value";

echo VAR_NAME;

echo ${VAR_NAME};

?>

a) testtest

b) testvalue

c) error, constant value cannot be changed

P R E P A R E D B Y GEMECHU . A Page 17
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

d) test

Explanation: ${VAR_NAME} creates a new variable that is not same as VAR_NAME.

36. Which PHP function displays the web page‟s most recent modification date?

a) getlastmod()

b) get_last_mod()

c) lastmod()

d) last_mod()

Explanation: The function getlastmod() gets the time of the last modification of the main script
of execution. It returns the value of the page‟s last modified header or FALSE in the case of an
error.

37. What will be the output of the following PHP program?

<?php

$i = 5;

while (--$i > 0 && ++$i)

print $i;

?>

a) 555555555…infinitely

b) 54321

c) error

d) 5

P R E P A R E D B Y GEMECHU . A Page 18
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

Explanation: As it is && operator it is being incremented and decremented continuously in PHP.

38. What will be the output of the following PHP code?

<?php

function constant()

define("GREETING", "Welcome to Sanfoundry",true);

echo greeting;

?>

a) GREETING

b) Welcome to Sanfoundry

c) ERROR

d) greeting

Explanation: By default, constants are case sensitive in php. But the third parameter in define(),
if set to true, makes constants case insensitive.

39. Which variable is used to collect form data sent with both the GET and POST methods?

a) $_BOTH

b) $REQUEST

c) $_REQUEST

d) $BOTH

Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an
HTML form.

P R E P A R E D B Y GEMECHU . A Page 19
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

40. What will be the output of the following PHP program?

<?php

$php = array("Array", "Function", "Strings", "File");

echo pos($php);

?>

a) Function

b) File

c) Strings

d) Array

Explanation: The pos() function returns the value of the current element in an array, and since no
operation has been done, the current element is the first element.

41. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

a) 1

b) 5

c) 12

d) Error

Explanation: ?: is known as ternary operator. If condition is true then the part just after the ? is
executed else the part after : .

JavaScript Multiple-Choice Questions

42. The ” var” and “function” are known as .

a. Data types

b. Keywords

P R E P A R E D B Y GEMECHU . A Page 20
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

c. Prototypes

d. Declaration statements

43. Which of these is the correct way in which we can call the JavaScript code?

a. Triggering Event

b. Preprocessor

c. Function/Method

d. RMI

44. Which of these functions of the Number Object would format a number with different
numbers of digits to the decimal‟s right?

a. toFixed()

b. toExponential()

c. toLocaleString()

d. toPrecision()

45. Out of the following functions of the string object, which one would return the character in
any string via the specified number of characters starting at a specified position?

a. search()

b. substr()

c. split()

d. slice()

46. Look at the snippets given below and check the one in which the variable “a” isn‟t equal to
the “NULL”.

a. if (a!)

P R E P A R E D B Y GEMECHU . A Page 21
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

b. if(a!=null)

c. if(a!==null)

d. if(a!null)

47. In JavaScript, what do we use for calling the expression for function definition?

a. Function literal

b. Function prototype

c. Function declaration

d. Function calling

48. Which of these is used in JavaScript for calling a method or a function?

a. Functional Expression

b. Property Access Expression

c. Primary Expression

d. Invocation Expression

8. Which of these operators are used for checking if a specific property exists?

a. in

b. within

c. exist

d. exists

49. “The expression that can appear legally on an assignment expression‟s left side” is a common
explanation for variables, elements of arrays, and properties of objects. These are known as
:

a. Prototypes

P R E P A R E D B Y GEMECHU . A Page 22
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

b. Properties

c. Lvalue

d. Definition

50. Which of these is a correct output for the JavaScript code given below?

string X= “Hey”;

string Y=”There”;

alert(X+Y);

a. Hey There

b. Hey_There

c. HeyThere

d. undefined

51. Which of these is known as the Equality operator used for checking whether both the values
are equal?

a. =

b. ==

c. ===

d. &&

52. In case a value of an operator is NULL, then the unary operator would return the
typeof.

a. object

b. boolean

c. string

P R E P A R E D B Y GEMECHU . A Page 23
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

d. undefined

53. Which of these is not a keyword?

a. debugger

b. use strict

c. with

d. if

54. Which of these symbols is used to create comments in JavaScript?

a. //

b. \\

c. \* */

d. \* *\

55. In the line of code given below, what will the “datatype” written in brackets be called?

article[datatype]=assignment_value;

a. An object

b. A String

c. Floating point

d. An integer

56. In the line of code given below, the prototype represents the .

functionx(){};

a. Prototype of a function

b. Function x

P R E P A R E D B Y GEMECHU . A Page 24
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

c. Not valid

d. A custom constructor

57. Which of these methods or operators are used for identifying an array?

a. isarrayType()

b. ===

c. ==

d. Typeof

58. A function‟s execution would stop whenever a program control would encounter the
statement in the function‟s body.

a. goto statement

b. break statement

c. continue statement

d. return statement

59. Which of these codes is equivalent to the code given below?

a.x(g,h);

a. a [ “x” ] ( g , h );

b. x (g) &&a.x (h);

c. x( g&&h );

d. a (x )[ “g” , “h” ];

60. Which of these keywords is used to define various functions in JavaScript?

a. function

P R E P A R E D B Y GEMECHU . A Page 25
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

b. main

c. init

d. Void

61. How to check the number of elements inside the HTML form?

a. document.form.elements.count

b. document.form.count

c. document.form.length

d. document.form.elements.length

62. Which javascript method returns the string starting at the specified position?

a. substr()
b. getSubstring()
c. slice()
d. None of the above

63. Which the method is used to refresh the webpage?

a. window.reload()
b. location.reload()
c. window.refresh()
d. location.refresh()

64. How to write "Hello world" in alert Box in Javascript?

a. showalert("Hello World");
b. msg("Hello World");
c. alert("Hello World");
d. msgBox("Hello world");

65. How to write a comment in Javascript?

P R E P A R E D B Y GEMECHU.A Page 26
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

a. /*This is a comment*/

b. $$This is a comment$$

c. **This is a comment**

d. // This is a comment

66. Which of the following is Popup box in JavaScript?

a. Alert

b. Confirm

c. Prompt

d. All of the above

67. What is the correct syntax for referring to an external script file called : tags.js"?

a. <script src="tags.js">

b. <script name="tags.js">

c. <script href="tags.js">

d. None of the above

68. what ignores JavaScript?

a. space

b. tabs

c. new lines

d. All of the above

69. Which of the following is not a loop in Javascript?

a. for

P R E P A R E D GEMECHU.A Page 27
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

b. while

c. foreach

d. forwhile

70. Which one is a ternary operator?

a. <?

b. ?:

c. >=

d.<>

71. Which of the following attribute is used to include external js code inside your HTML?

a. src

b. href

c. link

d. class

72. which of the following keyword is used to declare a variable?

a. var

b. function

c. char

d. const

73. What's the output of the following code?

let c = { message: 'Hello!' };

let d;

P R E P A R E D GEMECHU.A Page 28
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

d = c;

c.greeting = 'BBBootstrap';

console.log(d.message);

a. Hello!
b. undefined
c. ReferenceError
d. BBBoorstrap

74. What will be the output of the following code?

let a = 25;

let c = 25;

let b = new Number(25);

console.log(a == b);

console.log(a === b);

console.log(b == c);

a. false true false


b. false false true
c. true false true
d. true true true

75. what's output of the following code?

let message;

messge = {};

console.log(message);

a. undefined

P R E P A R E D GEMECHU.A Page 29
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

b. Reference Error
c. {}
d. None of the above

Check Answer

Correct Answer - 1. undefined

76. Which method is used for debuging purpose in javascript?

a. console.message("hello")

b. console.log("hello");

c. log("hello")

d. message("hello");

77. What will be the output?

let x = 5+3+"3";

Console.log(x);

a. 11
b. 8
c. 83
d. None of the above

Correct Answer - 3. 83

78. DOM stands for in javascript?

a. Document Object Model

b. Document Object Manipulation

c. Document Objective Model

P R E P A R E D GEMECHU.A Page 30
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

d. None of these

79. Which of the keyword is used to define the variable in the javascript?

a. var

b. let

c. Both A & B

d. None of the above

80. which of the method is used to get HTML element in javascript?

a. getElementbyId()

b. getElementsByClassName()

c. Both A & B

d. None of the above

81. What does NaN means?

a. Negative Number

b. Not a Number

c. Both A & B

d. None of the Above

82. How do we put Javascript inside HTML?

a. <js>

b. <javascript>

c. <scripting>

d. <script>

P R E P A R E D GEMECHU.A Page 31
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

83. What will be the output?

function myfunc() {

console.log(name);

console.log(age);

var name = 'BBBootstrap';

let age = 21;

myfunc();

a. undefined and ReferenceError


b. BBBootstrap and undefined
c. ReferenceError and 21
d. BBBootstrap and ReferenceError

84. What's the output of the following code?

for (var i = 0; i < 3; i++) {

setTimeout(() => console.log(i), 1);

a. 1 1 1
b. 3 2 1
c. 3 3 3
d. 1 2 3

85. Which one is true?

const bird = {

size: 'small',

P R E P A R E D GEMECHU.A Page 32
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

};

const mouse = {

name: 'Mickey',

small: true,

};

a. mouse[bird["size"]] is not valid


b. mouse.bird.size is not valid
c. mouse[bird.size] is not valid
d. All of them are valid

86. Which one is not a comparison operator?

a. =

b. <

c. >

d. !=

87. Which type of JavaScript language is?

a. Object oriented

b. Object based

c. Functional

d. None of above

88. Which symbol is used separate JavaScript statements?

Comma(,)

Colon(:)

P R E P A R E D GEMECHU.A Page 33
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

Hyphen(_)

Semicolon(;)

89. What is JavaScript?

a) JavaScript is a scripting language used to make the website interactive

b) JavaScript is an assembly language used to make the website interactive

c) JavaScript is a compiled language used to make the website interactive

d) None of the mentioned

Explanation: JavaScript is a scripting language used along with HTML and CSS to make the
website interactive along. It is used both on the client-side and server-side.

90. Which of the following is correct about JavaScript?

a) JavaScript is an Object-Based language

b) JavaScript is Assembly-language

c) JavaScript is an Object-Oriented language

d) JavaScript is a High-level language

Explanation: Although JavaScript is not an OOP (Object-Oriented Programming) language like


Java or PHP, it is object based language. The standard threesome of polymorphism,
encapsulation, and inheritance are the criteria for object orientation, and JavaScript fails to meet
them.

91. Among the given statements, which statement defines closures in JavaScript?

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

b) JavaScript is a function that is enclosed with references to its lexical environment

c) JavaScript is a function that is enclosed with the object to its inner function scope

P R E P A R E D GEMECHU.A Page 34
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

d) None of the mentioned

Explanation: A closure is a function that is enclosed with references to its lexical environment. A
closure allows an inner function to access the scope of an outside function. Closures are formed
every time a function is created in JavaScript, during function creation time.

92. 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;

a) error

b) Sanfoundry_ Javascriptmcq

c) undefined

d) Sanfoundry_Javascriptmcq

Explanation: The + operator in javascript acts as a concatenation operator when used with string.
The new string does not have any space between the two added strings.

93. 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>

P R E P A R E D GEMECHU.A Page 35
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

a) 10

b) 50

c) 5

d) Error

Explanation: The *= operator in javascript is a shorthand expression for the multiplication of a


particular number. It is a combination of two operators * and = .

94. Arrays in JavaScript are defined by which of the following statements?

a) It is an ordered list of values

b) It is an ordered list of objects

c) It is an ordered list of string

d) It is an ordered list of functions

Explanation: An array in JavaScript is an ordered list of values, each value is referred to as an


element, and it is identified by an index. An array can include values of many sorts and the
length of an array dynamically sized.

95. 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;

P R E P A R E D GEMECHU.A Page 36
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

else

return false;

a) false

b) true

c) compilation error

d) runtime error

Explanation: The == in JS convert different types of operands to the same type before making
the comparison. A strict comparison results in true value if the operands are of the same type and
the contents match.

96. Which of the following is not javascript data types?

a) Null type

b) Undefined type

c) Number type

d) All of the mentioned

Explanation: JavaScript is a dynamic, loosely typed language. Variables in JavaScript aren‟t tied
to any specific value type, and each variable can be assigned and reassigned to values of all the
types.

97. Where is Client-side JavaScript code is embedded within HTML documents?

a) A URL that uses the special javascript:code

b) A URL that uses the special javascript:protocol

c) A URL that uses the special javascript:encoding

P R E P A R E D GEMECHU.A Page 37
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2025

d) A URL that uses the special javascript:stack

Explanation: The Client-side JavaScript code is embedded within HTML documents in four
ways :

Inline, between a pair of “script” tags

From an external file specified by the src attribute of a “script” tag

In an HTML event handler attribute, such as onclick or onmouseover

In a URL that uses the special javascript: protocol.

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

a) Position

b) Window

c) Standard

d) Location

Explanation: All client-side JavaScript features and APIs are accessed through the Window
object. It represents a web browser window or frame, and the identifier window can be used to
refer to it.

99. What will be the output of the following JavaScript program?

function sanfoundry(javascript)

return (javascript ? “yes” : “no”);

bool ans=true;

P R E P A R E D GEMECHU.A Page 38
WEBSITE DEVELOPMENT MGT AND PHP WORKSHEET 2023

console.log(sanfoundry(ans));

a) Compilation error

b) Runtime error

c) Yes

d) No

Explanation: In javascript, “?” is called the ternary operator which is used for choosing one
choice from the given two choices. It is used instead of if else statement and makes the code
shorter.

100. 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;

a) short

b) 123.56

c) tall

d) 190

P R E P A R E D B Y GEMECHU .A Page 39

You might also like