Basic Javascript Test 1 - 200 Points
Basic Javascript Test 1 - 200 Points
14 sep 2024
Time - 4hr : 00 mins
1. Explain the differences between var, let, and const. Provide examples to
illustrate variable scope in JavaScript.
2. The filter() method returns the first element that matches the criteria
provided in a function. (T/F)
3. In JavaScript, functions are considered first-class objects. (T/F)
4. Which of the following is NOT a primitive data type in JavaScript?
a. String
b. Number
c. Object
d. boolean
5. Which method does NOT modify the original array?
a. push()
b. pop()
c. map()
d. splice()
6. Which keyword is NOT used for variable declaration in JavaScript?
a. Let
b. Var
c. Dim
d. const
7. Which is NOT a valid looping construct in JavaScript?
a. For
b. Foreach
c. While
d. do...while
8. The ________ operator in JavaScript is used to check both value and type for
equality.
9. The ________ keyword is used to declare a variable that cannot be reassigned.
10.What is the purpose of the throw statement?
11.To convert a string to an integer in JavaScript, you can use the ________
function.
12.The ________ method can be used to find the index of a specific element in an
array.
13.The switch statement can only evaluate expressions that return primitive
values
14.JavaScript is a statically typed language (T/F).
15.In JavaScript, all objects are stored by reference. (T/F)
16.The finally block will always execute after a try block, even if an error is
thrown. (T/F)
17.Which keyword is used to define a JavaScript class?
a. Function
b. Object
c. Class
d. constructor
18.What are template literals in JavaScript, and how do they differ from regular
strings?
19.The reduce() method executes a reducer function for each value of the array
from right to left. (T/F)
20.The delete operator can remove a property from an object. (T/F)
21.JavaScript does not support the concept of classes. (T/F)
22.Which of the following is NOT a method of JavaScript objects?
a. Object.keys()
b. Object.values()
c. Object.map()
d. Object.entries()
23.The ________ keyword is used to refer to the current instance of an object in a
class or function.
24.Which method can be used to merge two or more arrays in JavaScript?
a. concat()
b. merge()
c. combine()
d. join()
25.Explain the concept of "hoisting" in JavaScript with examples for variables
and functions.
26.Describe how the reduce() method works in JavaScript and provide an
example of its use.
27.What is the concept of "destructuring" in JavaScript? Provide examples of
both array and object destructuring.
28.Explain how JavaScript handles "scope" with examples of global scope, local
scope, block scope, and lexical scope.
29.Describe the spread operator (...) and its various use cases in JavaScript.
Provide examples for each.
30.Which of the following does NOT belong to JavaScript String methods?
a. toUpperCase()
b. toLowerCase()
c. round()
d. trim()
31.What will be the result of str.substring(3, 7) if str = "TypeScript"?
32.How does str.substring(3, 7) differ from str.substring(7, 3) for str =
"Functionality"?
33. What will be the output of str.substring(-2, 4) for str = "Python"? Explain why.
34.How do you get the current year from a Date object?
35.How would you compare two dates, date1 as 2024-08-15 and date2 as
2023-08-15, to check which one comes first?
36.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
You're given an array of user input strings representing numbers. Your task is to
write a function that:
. Validates each input to ensure it can be converted to a number.
. Converts each valid string to a number.
. If any input is invalid (i.e., cannot be converted to a number), the function
should throw an error with a descriptive message.
. Returns an array of the valid numbers in sorted order.
. If the array is empty after filtering out invalid inputs, return an error message
saying "No valid numbers found."
3. Find the Longest Word: Write a function that takes a sentence as input and
returns the longest word in the sentence. If there are multiple words with the
same length, return the first one.
Input: "The quick brown fox jumps over the lazy dog"
Output: "jumps"
4. Validate Phone Numbers: Write a function that takes an array of phone numbers
and checks if they follow a specific format (e.g., (123) 456-7890). Return an array
of valid phone numbers. If no valid phone numbers are found, return an error
message saying "No valid phone numbers found."
Input: [1, 2, 4, 6, 7, 9]
Output: [3, 5, 8]
6. Generate an Acronym: Write a function that takes a phrase and returns its
acronym formed by the first letter of each word in uppercase.
Output: "OOP"
7. Flatten a Nested Object: Write a function that takes a nested object and flattens it
into a single-level object with dot notation keys.
Input: { a: 1, b: { c: 2, d: { e: 3 } } }
8. Find the First Non-Repeating Character: Write a function that takes a string as
input and returns the first non-repeating character. If all characters repeat, return
an error message saying "No non-repeating character found."
Input: "swiss"
Output: "w"
9. You need to create a Student Grade Management System using JavaScript that
performs the following tasks:
Additional Requirements: