Test your understanding of core JavaScript concepts relevant to QA roles in Cypress and Playwright. This easy quiz covers variables, asynchronous programming, promises, TypeScript basics, object and function syntax, array methods, and more.
Variable Scope and Declaration
Which keyword in JavaScript creates a block-scoped variable that can be reassigned, but not redeclared within the same scope?
- let
- const
- var
- vet
Immutability of const
If you declare an array using const in JavaScript, which statement is true?
- You can change the elements of the array, but not reassign the array variable.
- You cannot change the elements of the array at all.
- You can redeclare the variable in the same scope.
- You can reassign the array variable to a string.
Synchronous vs Asynchronous
In JavaScript, what is the main characteristic of asynchronous programming in relation to task execution?
- Tasks are always processed in the order they appear
- Tasks allow others to run while waiting for longer tasks to complete
- Tasks execute simultaneously with guaranteed timing
- Tasks block each other until each has finished
Promise Handling
Which of the following methods is used to handle errors from JavaScript Promises?
- .always()
- .fail()
- .catch()
- .then()
Promise State
A newly created JavaScript Promise is in which state before it is resolved or rejected?
- Pending
- Fulfilled
- Cancelled
- Resolved
TypeScript Basics
How is TypeScript different from JavaScript with regard to variable types?
- TypeScript does not allow any type checking.
- JavaScript is a superset of TypeScript.
- JavaScript supports types for variables at compile time.
- TypeScript requires types defined for variables, enabling compile-time checks.
Objects vs Functions
Which statement correctly distinguishes a JavaScript object from a function?
- Functions can be properties of objects, but objects primarily store key-value pairs.
- Objects must always have a name, functions do not.
- Functions store multiple key-value pairs; objects do not.
- Objects can only contain primitive values, functions cannot.
Array Method Usage
If you want to create a new array containing only even numbers from [1, 2, 3, 4, 5], which JavaScript array method should you use?
- filter()
- reduce()
- find()
- map()
String Manipulation
Given let str = 'Test'; which method returns the uppercase version of the string?
- str.toLower()
- str.isUpperCase()
- str.toUpperCase()
- str.uppercase()
Class Syntax
Which syntax correctly creates a JavaScript class named Animal with a constructor?
- new class Animal() { }
- let Animal = () =u003E { }
- Animal = function() { }
- class Animal { constructor() { } }