Follow and like us on our Facebook page where we post on the new release subject and answering tips and tricks to help save your time so that you can never feel stuck again.
Shortcut

Ctrl + F is the shortcut in your browser or operating system that allows you to find words or questions quickly.

Ctrl + Tab to move to the next tab to the right and Ctrl + Shift + Tab to move to the next tab to the left.

On a phone or tablet, tap the menu icon in the upper-right corner of the window; Select "Find in Page" to search a question.

Share Us

Sharing is Caring

It's the biggest motivation to help us to make the site better by sharing this to your friends or classmates.

Javascript Algorithms and Data Structures

Explore JavaScript Algorithms and Data Structures to enhance your programming skills, solving complex problems efficiently and mastering data manipulation.

variables

functions

loops

arrays

objects

linked lists

stacks

queues

recursion

sorting

searching

trees

graphs

hashing

algorithms

What is the purpose of the "keys" method in JavaScript objects?

  • It returns an array of all values in the object.
  • It returns an array of all properties in the object.
  • It returns an array of all property names in the object.
  • It returns an array of all methods in the object.

What method joins two arrays together?

  • concat

How can you implement a matrix in javascript?

  • an array of arrays

Which of the following is NOT a valid way to create a function in JavaScript?

  • function myFunction() {}
  • myFunction = function() {};
  • const myFunction = () => {};
  • myFunction = () => {};

Which of the following is NOT a valid primitive data type in JavaScript?

  • Boolean
  • Date
  • Number
  • String

What is another name for a two-dimensional array?

  • matrix

Which of the following is used to declare a constant variable in JavaScript?

  • const
  • let
  • var

Which of the following is true about the "break" statement in JavaScript?

  • It is used to exit a function.
  • It is used to skip the current iteration of a loop and move to the next one.
  • It is used to terminate the execution of a loop or switch statement.
  • It is used to catch and handle errors in a try-catch block.

In JavaScript, what is the purpose of the "map" method for arrays?

  • It creates a new array with all elements that pass a certain test.
  • It creates a new array by performing a specified action on each element of the original array.
  • It returns the first element of the array.
  • It combines two arrays into a single array.

What does the acronym DOM stand for in the context of web development?

  • Document Object Model
  • Dynamic Order Management
  • Digital Output Mode

What does the "split" method do in JavaScript?

  • It joins elements of an array into a single string.
  • It divides a string into an array of substrings based on a specified separator.
  • It replaces a substring in a string with another substring.
  • It removes all occurrences of a specified substring from a string.

What does the "typeof" operator return when applied to an array in JavaScript?

  • "object"
  • "array"
  • "array-like"

What is the purpose of the "return" statement in a JavaScript function?

  • It specifies the value that the function should output.
  • It terminates the execution of the function immediately.
  • It defines a variable with a specific value.
  • It declares a loop within the function.

What does the "push" method return after adding an element to an array?

  • The new length of the array
  • The added element
  • The updated array
  • The index of the added element

Which statement is used to exit or "break" out of a loop in JavaScript?

  • return
  • break
  • exit

What array method allows us to remove an element in the beginning of an array?

  • shift

What stores a sequence of values that are all of the same data type?

  • array

Which of the following is used to round a number up to the nearest integer in JavaScript?

  • round()
  • Math.ceil()
  • Math.floor()
  • Math.roundUp()

What does the "splice" method do in JavaScript?

  • It removes an element from the end of an array.
  • It allows you to add or remove elements from a specific position in an array.
  • It reverses the order of elements in an array.
  • It returns a shallow copy of an array.

Which of the following is NOT a valid loop in JavaScript?

  • repeat loop
  • for loop
  • while loop
  • do...while loop

What is the purpose of the "concat" method for arrays in JavaScript?

  • It combines two arrays into a single array.
  • It combines two or more arrays and returns a new array.
  • It creates a copy of an array.
  • It adds an element to the beginning of an array.

What is the purpose of the "parseFloat" function in JavaScript?

  • It converts a string to a floating-point number.
  • It converts a number to a string.
  • It rounds a floating-point number to the nearest integer.
  • It returns the fractional part of a number.

What is the purpose of the "push" method in JavaScript arrays?

  • It removes the last element from the array.
  • It adds a new element to the beginning of the array.
  • It adds a new element to the end of the array.
  • It reverses the order of the elements in the array.

What is the purpose of the "find" method for arrays in JavaScript?

  • It checks if any element in the array passes a certain test defined by a provided function.
  • It returns the index of the first element that passes a certain test.
  • It returns the first element in the array that passes a certain test defined by a provided function.
  • It removes all elements that pass a certain test from the array.

Which built-in JavaScript function is used to round a number to the nearest integer?

  • round()
  • Math.round()
  • floor()
  • ceil()

What does the "length" property of an array in JavaScript represent?

  • The number of elements in the array
  • The sum of the values of all elements in the array
  • The average value of the elements in the array

Which of the following is a valid way to create a new object in JavaScript?

  • newObject = Object.create();
  • newObject = {};
  • newObject = new Object();
  • newObject = Object.new();

What do the shift and unshift methods allow an array to emulate?

  • queue

What does the term "hoisting" refer to in JavaScript?

  • The process of elevating a function call to the top of the call stack
  • The behavior of moving variable and function declarations to the top of their containing scope during compilation
  • A way to optimize asynchronous code execution
  • The process of converting data types automatically

Which data structure follows the "Last In, First Out" (LIFO) principle?

  • Queue
  • Linked List
  • Stack
  • Hash Table

Which of the following methods is used to convert a string to uppercase in JavaScript?

  • toUpper()
  • upper()
  • toUpperCase()
  • uppercase()

What does the term "asynchronous" mean in the context of JavaScript?

  • It refers to code that doesn't necessarily execute in a linear, top-to-bottom order, allowing other code to run in the meantime.
  • It describes code that only runs on alternate days.
  • It refers to code that executes instantly without any delay.
  • It describes code that runs only when the browser is offline.

What is the purpose of the "isNaN" function in JavaScript?

  • It checks if a variable is of the data type "NaN".
  • It checks if a value is "Not-a-Number".
  • It converts a value to the data type "NaN".
  • It checks if a value is null or undefined.

What is the main difference between "==" and "===" in JavaScript?

  • "==" performs a strict equality comparison, while "===" performs a loose equality comparison.
  • "==" compares values and types, while "===" only compares values.
  • "==" performs type coercion, while "===" requires both values to be of the same type.
  • There is no difference; "==" and "===" are interchangeable.

Which method is used to remove the first element from an array in JavaScript?

  • shift()
  • removeFirst()
  • deleteFirst()

What does the "splice" method return after removing elements from an array?

  • An array containing the removed elements
  • The index of the first removed element
  • The number of elements removed
  • The updated array with the elements removed

What does the "charAt" method return when passed an index that is out of range in a string?

  • An empty string
  • null
  • undefined
  • An error message

What does the "toUpperCase" method do in JavaScript?

  • It converts a string to uppercase.
  • It converts a string to lowercase.
  • It checks if a string contains only uppercase characters.
  • It removes all whitespace from a string.

Which keyword is used to declare a function in JavaScript?

  • func
  • function
  • method

What does the "isNaN" function return when passed an empty string ("")?

  • false
  • true
  • null
  • undefined

What is the purpose of the "filter" method for arrays in JavaScript?

  • It removes elements from the array that meet a certain condition.
  • It creates a new array with all elements that pass a certain test defined by a provided function.
  • It returns the index of the first element that passes a certain test.
  • It sorts the elements of the array in ascending order.

What is the purpose of the "shift" method in JavaScript arrays?

  • It adds a new element to the beginning of an array.
  • It removes the first element from an array.
  • It reverses the order of elements in an array.

What is a data structure where we can have rows and columns?

  • two-dimensional array

What does the "isNaN" function return when passed the value "undefined"?

  • true
  • false
  • null
  • undefined

Which of the following is used to add a comment within an HTML file that won't be visible on the webpage?

  • <!~Hasdoublearr~ This is a comment ~Hasdoublearr~>
  • // This is a comment
  • /* This is a comment */

Which of the following is used to store and manage key-value pairs in JavaScript?

  • Array
  • List
  • Object
  • Tuple

What does the term "closure" refer to in JavaScript?

  • A function that has no return statement.
  • A function that retains access to its outer function's variables even after the outer function has finished executing.
  • A function with no parameters.
  • A function that can only be called once.

What does the "typeof" operator in JavaScript return?

  • The data type of a variable
  • A string indicating the data type of a value
  • The memory address of a variable
  • The size of an object

What is the purpose of the "every" method for arrays in JavaScript?

  • It checks if all elements in an array pass a certain test defined by a provided function.
  • It adds a new element to the beginning of an array.
  • It removes elements from the array that meet a certain condition.
  • It combines two arrays into a single array.

What does the "isNaN" function return when passed the value "null"?

  • false
  • true
  • null

Which of the following methods is used to remove the last element from an array in JavaScript?

  • pop()
  • pop()
  • removeLast()
  • delete()
  • All of the above

Which of the following is used to declare a global variable in JavaScript?

  • var
  • global
  • let

Which of the following is a valid way to comment a single line of code in JavaScript?

  • // This is a comment
  • /* This is a comment */
  • <!~Hasdoublearr~ This is a comment ~Hasdoublearr~>

What is the purpose of the "Math.random" function in JavaScript?

  • It generates a random floating-point number between 0 (inclusive) and 1 (exclusive).
  • It generates a random integer between 0 and a specified maximum value.
  • It generates a random number between a specified minimum and maximum value.
  • It generates a random boolean value.

What is the purpose of the "startsWith" method in JavaScript?

  • It checks if a string starts with a specified substring.
  • It returns the index of the first occurrence of a substring in a string.
  • It replaces the first occurrence of a substring with another substring in a string.
  • It removes the first character from a string.

Which of the following is a comparison operator in JavaScript?

  • &
  • ==
  • ><

What does the "push" method do in JavaScript when applied to a string?

  • It adds a new character to the beginning of the string.
  • It adds a new character to the end of the string.
  • It removes the last character from the string.
  • It replaces a specified character with another character in the string.

Which keyword is used to declare a constant variable in JavaScript?

  • const
  • let
  • var

Which of the following is true about the "continue" statement in JavaScript?

  • It is used to skip the current iteration of a loop and move to the next one.
  • It is used to exit a loop.
  • It is used to catch and handle errors in a try-catch block.
  • It is used to restart the loop from the beginning.

What is the purpose of the "Math.max" function in JavaScript?

  • It returns the largest of zero or more numbers.
  • It returns the smallest of zero or more numbers.
  • It rounds a number to the nearest integer.
  • It calculates the absolute value of a number.

What is the purpose of the "join" method for arrays in JavaScript?

  • It combines all the elements of an array into a single string, using a specified separator.
  • It adds a new element to the end of the array.
  • It removes all occurrences of a specific element from the array.
  • It reverses the order of elements in the array.

What does the "lastIndexOf" method do in JavaScript?

  • It returns the index of the last occurrence of a specified substring in a string.
  • It returns the index of the first occurrence of a substring in a string.
  • It checks if a specific substring is present in a string.
  • It removes the last occurrence of a specified substring from a string.

What is the role of the "else" statement in an "if-else" construct?

  • It defines a new condition to be checked if the first "if" condition is false.
  • It provides an alternative code block to be executed if the initial "if" condition is false.
  • It marks the end of the "if" statement.
  • It is used to create a loop.

What is the purpose of the "Date" object in JavaScript?

  • It represents a specific moment in time and provides methods for working with dates and times.
  • It creates an array of date-related functions.
  • It formats strings in a date-like format.
  • It returns the current time in milliseconds.

What does the "indexOf" method return when the searched element is not found in an array?

  • -1
  • 0
  • null

What array method allows us to insert an element in the beginning of an array?

  • unshift

Which built-in method is used to sort elements in an array in JavaScript?

  • order()
  • sort()
  • arrange()

What is the primary difference between "null" and "undefined" in JavaScript?

  • "null" is a value that represents the intentional absence of any object value, while "undefined" indicates a variable that has been declared but hasn't been assigned a value.
  • They are interchangeable and can be used in the same contexts.
  • "undefined" is a value that represents the intentional absence of any object value, while "null" indicates a variable that has been declared but hasn't been assigned a value.
  • "null" is a reserved keyword, while "undefined" is not.

What array method allows us to add an element to the end?

  • push

Which function is used to convert a JSON string into a JavaScript object?

  • parseJSON()
  • JSON.parse()
  • fromJSON()
  • stringifyJSON()

Which of the following is the correct way to declare a multi-dimensional array in JavaScript?

  • var matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
  • var matrix = {1, 2, 3; 4, 5, 6; 7, 8, 9};
  • var matrix = [1, 2, 3][4, 5, 6][7, 8, 9];
  • var matrix = new Array[1, 2, 3][4, 5, 6][7, 8, 9];

What is the purpose of the "reverse" method for arrays in JavaScript?

  • It sorts the elements of an array in descending order.
  • It reverses the order of elements in an array.
  • It removes the last element from an array.
  • It adds a new element to the beginning of an array.

Which of the following is used to create a new array by applying a function to each element of an existing array?

  • map()
  • filter()
  • reduce()
  • forEach()

Which of the following is NOT a valid way to declare a string in JavaScript?

  • string myString = "Hello";
  • var myString = "Hello";
  • const myString = "Hello";
  • let myString = "Hello";

What array method allows us to remove an element by simply specifying the position/index, and how many elements we would like to remove?

  • splice

What does the "splice" method do in JavaScript when used with only one argument?

  • It removes a specified number of elements from an array, starting from the beginning.
  • It removes a specified number of elements from an array, starting from the specified index.
  • It adds a new element to the beginning of an array.
  • It adds a new element to the end of an array.

What is the purpose of the "reduce" method for arrays in JavaScript?

  • It adds up all the elements of the array.
  • It creates a new array by applying a function to each element.
  • It reduces the array to a single value by applying a function to each element and accumulating the result.
  • It removes elements from the array that meet a certain condition.

What does the "substr" method do in JavaScript?

  • It returns a new string with a specified number of characters removed from the beginning.
  • It returns a new string with a specified number of characters removed from the end.
  • It returns a substring of a string, starting at a specified position and ending at the specified position.

What is the output of the following code snippet? console.log(2 + "2");

  • 22
  • 4
  • "22"

Which type of loop is guaranteed to execute at least once?

  • while loop
  • do...while loop
  • for loop
  • if loop

What is the purpose of the "concat" method in JavaScript when used with strings?

  • It combines two or more strings and returns a new string.
  • It adds a new character to the end of a string.
  • It replaces a substring with another substring in a string.
  • It checks if a string contains a specific substring.

Which operator is used to compare two values for equality in JavaScript?

  • ==
  • =
  • !=

What does the "toLowerCase" method do in JavaScript?

  • It converts a string to lowercase.
  • It checks if a string contains only lowercase characters.
  • It converts a string to uppercase.
  • It removes all whitespace from a string.

Which of the following is a valid way to define a function with parameters in JavaScript?

  • function myFunction(parameter1, parameter2) {}
  • const myFunction = parameter1, parameter2 => {}
  • myFunction = function(parameter1, parameter2) {}

Which of the following is used to perform asynchronous programming in JavaScript?

  • Promises
  • Promises
  • Callbacks
  • Async/Await
  • All of the above

Which of the following is NOT a valid way to declare a variable in JavaScript?

  • var myVar = 10;
  • let anotherVar = "Hello";
  • const PI = 3.14;
  • variable myVar = 10;

What is the purpose of the "unshift" method in JavaScript arrays?

  • It removes the first element from an array.
  • It adds a new element to the beginning of an array.
  • It adds one or
  • more elements to the beginning of an array and returns the new length.
  • It reverses the order of elements in an array.

What does the "trim" method do in JavaScript?

  • It removes whitespace from both ends of a string.
  • It adds whitespace to both ends of a string.
  • It removes all occurrences of a specific character from a string.
  • It converts a string to uppercase.

Which of the following is used to create an empty object in JavaScript?

  • new object()
  • {}
  • emptyObject()
  • object = Object.create()

Which of the following is used to remove the first element from an array in JavaScript?

  • removeFirst()
  • shift()
  • pop()

What does the "charAt" method do in JavaScript?

  • It removes the character at a specified position in a string.
  • It returns the character at a specified position in a string.
  • It checks if a specific character is present in a string.
  • It adds a new character to the end of a string.

What is the purpose of the "toLocaleString" method in JavaScript?

  • It returns a string representing the object's value, formatted according to the conventions of the current locale.
  • It converts a string to lowercase and returns it.
  • It converts a number to a currency format and returns it as a string.
  • It checks if a string contains only lowercase characters.

What is the purpose of the "Math.pow" function in JavaScript?

  • It returns the square root of a number.
  • It returns the result of raising a number to a specified power.
  • It rounds a number to the nearest integer.
  • It calculates the absolute value of a number.

What does the "pop" method return when called on an empty array?

  • null
  • undefined
  • 0

What is the purpose of the "charAt" method in JavaScript?

  • It returns the character at a specified index in a string.
  • It removes the character at a specified index in a string.
  • It adds a new character at the end of a string.
  • It checks if a specific character is present in a string.

Which of the following is used to add a new element to the end of an array in JavaScript?

  • add()
  • push()
  • append()
  • insert()

Which operator is used to access a property or method of an object in JavaScript?

  • .
  • ,
  • ::
  • ;

What does the "toFixed" method do in JavaScript?

  • It formats a number with a specified number of decimal places and returns it as a string.
  • It rounds a number to the nearest integer and returns it as a string.
  • It converts a number to a fixed notation.
  • It returns the fractional part of a number as a string.

What is the purpose of the "length" property of a string in JavaScript?

  • It returns the number of characters in the string.
  • It returns the last character of the string.
  • It returns the first character of the string.
  • It returns the sum of the Unicode values of all characters in the string.

What does the "pop" method do in JavaScript?

  • It removes the first element from an array.
  • It removes the last element from an array.
  • It removes all elements with a specific value from an array.

What is the purpose of the "Math.floor" function in JavaScript?

  • It rounds a number down to the nearest integer.
  • It rounds a number up to the nearest integer.
  • It rounds a number to the nearest integer.
  • It returns the smallest integer greater than or equal to a number.

Which statement is used to catch and handle errors in JavaScript?

  • try
  • error
  • catch
  • handle

Which of the following is used to remove the last element from an array in JavaScript?

  • pop()
  • shift()
  • removeLast()
  • deleteLast()

What does the "NaN" acronym stand for?

  • Not a Normal number
  • Not a Number
  • No available Number
  • Null and None

What array method allows us to remove an element in the end of an array?

  • pop

What array method will iterate each element of the array until the return of the function is false?

  • every

Which of the following is a valid way to access the value of a property in a JavaScript object?

  • object.property
  • object[property]
  • object->property

What does the "charAt" method return when passed a negative index in a string?

  • An empty string
  • null
  • undefined
  • An error message

What is the purpose of the "slice" method for arrays in JavaScript?

  • It removes the last element from an array.
  • It returns a copy of a portion of an array, selected by specifying starting and ending indices.
  • It adds elements to an array based on a specified range.

What is the purpose of the "typeof" operator when used with the "function" keyword?

  • It returns "function" when applied to a function.
  • It checks if a variable is a function.
  • It returns the name of the function.
  • It returns the parameters of the function.

What is the role of the "continue" statement in a loop?

  • It terminates the loop and resumes execution from the beginning of the loop.
  • It skips the current iteration of the loop and continues with the next iteration.
  • It exits the loop immediately.
  • It restarts the loop from the beginning.
Comments