Unit 4: JavaScript Fundamentals - Practice Quiz

CSE326 — Internet Programming 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is JavaScript primarily used for in web development?

Introduction to JavaScript Easy
A. Managing files on a web server
B. Adding interactivity to web pages
C. Styling the appearance of web pages
D. Defining the structure of web pages

2 Which HTML element is used to include JavaScript code in a web page?

Introduction to JavaScript Easy
A. <meta>
B. <link>
C. <script>
D. <style>

3 Which keyword declares a block-scoped variable that can be reassigned?

Variables and Constants Easy
A. let
B. static
C. const
D. define

4 Which keyword declares a block-scoped binding that cannot be reassigned?

Variables and Constants Easy
A. const
B. let
C. value
D. var

5 What is the data type of the value "JavaScript"?

Data Types Easy
A. String
B. Undefined
C. Boolean
D. Number

6 Which JavaScript value represents an intentionally empty or absent value?

Data Types Easy
A. null
B. undefined
C. false
D. 0

7 Which operator checks both value and data type for equality?

Operators and Expressions Easy
A. !=
B. ===
C. ==
D. =

8 What is the result of the expression 10 % 3?

Operators and Expressions Easy
A. 1
B. 3
C. 3.33
D. 0

9 Which property returns the number of characters in a string named text?

Strings and String Methods Easy
A. text.size
B. text.count
C. text.length
D. text.width

10 Which method converts the string name to uppercase?

Strings and String Methods Easy
A. name.makeUpper()
B. name.toLowerCase()
C. name.toUpperCase()
D. name.upperCase()

11 Which pair contains the two Boolean values in JavaScript?

Numbers and Boolean Values Easy
A. on and off
B. true and false
C. yes and no
D. 1 and 0

12 What does Number("25") return?

Numbers and Boolean Values Easy
A. The string "25"
B. The Boolean true
C. The number 25
D. The value undefined

13 Which statement runs a block of code only when a specified condition is true?

Conditional Statements Easy
A. break statement
B. for statement
C. if statement
D. return statement

14 Which keyword provides an alternative block when an if condition is false?

Conditional Statements Easy
A. else
B. case
C. then
D. default

15 Which keyword is commonly used to declare a JavaScript function?

Functions Easy
A. define
B. procedure
C. function
D. method

16 Which keyword sends a value back from a function?

Functions Easy
A. output
B. return
C. yield
D. break

17 Where can a variable declared inside a function normally be accessed?

Scope Easy
A. Only inside HTML
B. Inside that function
C. Only in another function
D. Anywhere in the program

18 Which method adds an element to the end of an array?

Arrays and Array Operations Easy
A. pop()
B. push()
C. slice()
D. shift()

19 Which index accesses the first element of a JavaScript array named items?

Arrays and Array Operations Easy
A. items[0]
B. items[1]
C. items[first]
D. items[-1]

20 How can the name property of an object called student be accessed using dot notation?

Objects and Object Manipulation Easy
A. student(name)
B. student->name
C. student.name
D. student::name

21 What happens when a browser encounters <script defer src="app.js"></script> in the document <head>?

Introduction to JavaScript Medium
A. The script runs only after all images have loaded
B. The script downloads only after HTML parsing finishes
C. The script blocks HTML parsing until execution finishes
D. The script downloads in parallel and runs after HTML parsing

22 Given const user = { name: "Ana" };, which statement executes without causing an error?

Variables and Constants Medium
A. user.name = "Ben";
B. user = null;
C. user = { name: "Ben" };
D. const user = { name: "Ben" };

23 What is printed by console.log(typeof null, Array.isArray([]));?

Data Types Medium
A. object true
B. object false
C. undefined false
D. null true

24 What is the output of console.log(0 ?? 5, 0 || 5);?

Operators and Expressions Medium
A. 5 5
B. 0 0
C. 0 5
D. 5 0

25 What value is produced by the expression 2 + 3 * 4 ** 2?

Operators and Expressions Medium
A. 66
B. 50
C. 80
D. 196

26 What does "JavaScript".slice(4, 10) return?

Strings and String Methods Medium
A. "JavaS"
B. "cript"
C. "Script"
D. "Scrip"

27 What is printed by let text = " web "; text.trim().toUpperCase(); console.log(text.length);?

Strings and String Methods Medium
A. 3
B. 5
C. 4
D. 0

28 What is printed by console.log(Number.isNaN("hello"), isNaN("hello"));?

Numbers and Boolean Values Medium
A. true false
B. false false
C. true true
D. false true

29 What is the value of [0, 1, "", "JS", null].filter(Boolean).length?

Numbers and Boolean Values Medium
A. 4
B. 3
C. 2
D. 1

30 What is printed by const age = 20; const hasID = false; if (age >= 18 && hasID) { console.log("Enter"); } else if (age >= 18) { console.log("ID required"); } else { console.log("Too young"); }?

Conditional Statements Medium
A. Too young
B. Nothing is printed
C. ID required
D. Enter

31 What is printed by const value = "2"; switch (value) { case 2: console.log("number"); break; case "2": console.log("string"); break; default: console.log("other"); }?

Conditional Statements Medium
A. string
B. other
C. number string
D. number

32 What is returned by function total(price, tax = price * 0.1) { return price + tax; } total(200);?

Functions Medium
A. 220
B. 200
C. 210
D. NaN

33 What is the result of function twice(fn, value) { return fn(fn(value)); } twice(x => x + 3, 4);?

Functions Medium
A. 14
B. 11
C. 7
D. 10

34 What is printed by let count = 10; { let count = 20; console.log(count); } console.log(count);?

Scope Medium
A. 10 followed by 10
B. 10 followed by 20
C. 20 followed by 10
D. 20 followed by 20

35 What is returned by function makeFunctions() { const result = []; for (let i = 0; i < 3; i++) result.push(() => i); return result; } makeFunctions().map(fn => fn());?

Scope Medium
A. [0, 1, 2]
B. [1, 2, 3]
C. [0, 0, 0]
D. [3, 3, 3]

36 After const values = [1, 2, 3, 4]; const removed = values.splice(1, 2, 9);, what are values and removed?

Arrays and Array Operations Medium
A. values is [1, 9, 4]; removed is [2, 3]
B. values is [1, 2, 9, 4]; removed is [3]
C. values is [1, 9, 3, 4]; removed is [2]
D. values is [1, 4]; removed is [2, 3, 9]

37 What is the result of [1, 2, 3, 4].filter(n => n % 2 === 0).map(n => n * n)?

Arrays and Array Operations Medium
A. [2, 4]
B. [4, 16]
C. [1, 9]
D. [1, 4, 9, 16]

38 What value is returned by [2, 3, 4].reduce((product, n) => product * n, 1)?

Arrays and Array Operations Medium
A. 10
B. 14
C. 20
D. 24

39 What is printed by const original = { info: { score: 1 } }; const copy = { ...original }; copy.info.score = 5; console.log(original.info.score);?

Objects and Object Manipulation Medium
A. 1
B. 5
C. undefined
D. A TypeError occurs

40 What is printed by const item = { name: "Pen", price: 10 }; const { name: label, stock = 0 } = item; console.log(label, stock);?

Objects and Object Manipulation Medium
A. Pen undefined
B. label 10
C. name 0
D. Pen 0

41 What is printed by the following JavaScript code?

JAVASCRIPT
console.log("A");
Promise.resolve().then(() => console.log("B"));
queueMicrotask(() => console.log("C"));
setTimeout(() => console.log("E"), 0);
console.log("D");

Introduction to JavaScript Hard
A. A D B C E
B. A D E B C
C. A B C D E
D. A D C B E

42 What happens when this code executes?

JAVASCRIPT
let x = 1;

function test() {
  console.log(x);
  let x = 2;
}

test();

Variables and Constants Hard
A. It prints 1.
B. It throws a ReferenceError.
C. It prints 2.
D. It prints undefined.

43 In an ordinary non-strict script, what is printed?

JAVASCRIPT
const config = Object.freeze({
  nested: { value: 1 }
});

config.nested.value = 2;
config.nested = { value: 3 };
console.log(config.nested.value);

Variables and Constants Hard
A. undefined
B. 1
C. 2
D. 3

44 What is the value of result?

JAVASCRIPT
const value = Object.create(null);
const result = [
  typeof value,
  value instanceof Object,
  Object.getPrototypeOf(value)
];

Data Types Hard
A. ["object", true, null]
B. ["object", false, null]
C. ["object", false, Object.prototype]
D. ["null", false, null]

45 What are the final values of x and y?

JAVASCRIPT
let x = 0;
const y = x++ || ++x;

Operators and Expressions Hard
A. x is 2 and y is 2.
B. x is 1 and y is 0.
C. x is 2 and y is 1.
D. x is 1 and y is 1.

46 What happens when an ECMAScript parser processes this statement?

JAVASCRIPT
const result = null ?? false || true;

Operators and Expressions Hard
A. result becomes true.
B. A SyntaxError occurs.
C. result becomes null.
D. result becomes false.

47 What is the value of result?

JAVASCRIPT
const text = "A😀B";
const result = [
  text.length,
  text.slice(1, 3),
  Array.from(text).length
];

Strings and String Methods Hard
A. [4, "😀B", 3]
B. [4, "😀", 3]
C. [3, "😀", 4]
D. [3, "😀", 3]

48 What does the following expression return?

JAVASCRIPT
"aba".replace(/a/g, (match, offset) => String(offset))

Strings and String Methods Hard
A. "0b2"
B. "0ba"
C. "ab2"
D. "1b3"

49 What is the result of this comparison?

JAVASCRIPT
Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2

Numbers and Boolean Values Hard
A. A RangeError
B. false
C. undefined
D. true

50 What is the value of result?

JAVASCRIPT
const result = [
  Object.is(NaN, NaN),
  Object.is(0, -0),
  Boolean(new Boolean(false))
];

Numbers and Boolean Values Hard
A. [true, true, false]
B. [true, false, true]
C. [false, false, true]
D. [false, true, false]

51 What is the final value of result?

JAVASCRIPT
let result = "";

switch (2) {
  case 1:
    result += "A";
  case 2:
    result += "B";
  default:
    result += "C";
  case 3:
    result += "D";
}

Conditional Statements Hard
A. "BC"
B. "BCD"
C. "ABCD"
D. "BD"

52 What is the value of result after this code runs?

JAVASCRIPT
let a = 0;
let b = 1;
let result;

if (a = b && 0 || 2) {
  result = [a, "T"];
} else {
  result = [a, "F"];
}

Conditional Statements Hard
A. [0, "F"]
B. [2, "F"]
C. [2, "T"]
D. [1, "T"]

53 What happens when f() is called?

JAVASCRIPT
let x = 10;

function f(a = x, x = 20) {
  return [a, x];
}

f();

Functions Hard
A. It returns [10, 20].
B. It returns [undefined, 20].
C. It returns [20, 20].
D. It throws a ReferenceError.

54 What does the final expression return?

JAVASCRIPT
const obj = {
  x: 5,
  make() {
    return () => this.x;
  }
};

const fn = obj.make();
const other = { x: 9, fn };
other.fn();

Functions Hard
A. 9
B. undefined
C. 5
D. A TypeError

55 What string is produced?

JAVASCRIPT
const callbacks = [];

for (var i = 0; i < 3; i++) {
  let j = i;
  callbacks.push(() => `${i}:${j}`);
}

callbacks.map(fn => fn()).join(",");

Scope Hard
A. "0:0,1:1,2:2"
B. "3:0,3:1,3:2"
C. "3:3,3:3,3:3"
D. "0:3,1:3,2:3"

56 What is the value of result?

JAVASCRIPT
const source = [1, , 3];
const mapped = source.map(x => x * 2);
const result = [
  mapped.length,
  0 in mapped,
  1 in mapped,
  2 in mapped
];

Arrays and Array Operations Hard
A. [3, true, true, true]
B. [3, false, false, true]
C. [3, true, false, true]
D. [2, true, false, true]

57 After this code runs, what are removed and values?

JAVASCRIPT
const values = [1, 2, 3, 4];
const removed = values.splice(1, 2, 9, 8, 7);

Arrays and Array Operations Hard
A. removed = [2, 3], values = [1, 9, 8, 7, 4]
B. removed = [2, 3, 4], values = [1, 9, 8, 7]
C. removed = [9, 8], values = [1, 7, 3, 4]
D. removed = [2, 3], values = [1, 9, 8, 7]

58 What is the value of result?

JAVASCRIPT
const symbol = Symbol("1");
const object = {
  [1]: "first",
  "1": "second",
  [symbol]: "third"
};

const result = [
  Object.keys(object),
  object[1],
  Object.getOwnPropertySymbols(object).length
];

Objects and Object Manipulation Hard
A. [["1", symbol], "second", 1]
B. [["1"], "first", 0]
C. [["1", "1"], "first", 1]
D. [["1"], "second", 1]

59 What is the value of result?

JAVASCRIPT
const source = {
  get x() {
    return 2;
  }
};

const target = { ...source };
const descriptor = Object.getOwnPropertyDescriptor(target, "x");
const result = [target.x, typeof descriptor.get, descriptor.writable];

Objects and Object Manipulation Hard
A. [undefined, "undefined", true]
B. [2, "function", false]
C. [2, "undefined", true]
D. [2, "function", true]

60 What is the value of result?

JAVASCRIPT
const prototype = { x: 1 };
const object = Object.create(prototype);
object.x = 2;
delete object.x;

const result = [
  "x" in object,
  Object.hasOwn(object, "x"),
  object.x
];

Objects and Object Manipulation Hard
A. [false, true, 1]
B. [true, true, 2]
C. [true, false, 1]
D. [false, false, undefined]