20 difficult programming questions and answers designed for true quiz masters on Python and JavaScript.
1. What is 'list comprehension' in Python used for?
💡 List comprehension provides a concise syntax for creating lists based on existing iterables.
2. What is the 'event loop' in JavaScript responsible for?
💡 The event loop manages the execution of asynchronous operations, callbacks, and tasks in JavaScript's single-threaded environment.
3. What is a 'context manager' in Python, typically used with 'with'?
💡 A context manager, used with the 'with' statement, defines setup and teardown behavior for a block of code.
4. What is a 'decorator' in Python?
💡 A decorator wraps a function to modify or extend its behavior without changing its actual code.
5. What does 'this' refer to in a regular JavaScript function (non-arrow)?
💡 The value of 'this' in a regular function is determined dynamically by how the function is called.
6. What is a 'generator' in Python?
💡 A generator is a special function that yields values one at a time, pausing its state between each yield.
7. What is 'duck typing' in Python?
💡 Duck typing focuses on what an object can do (its methods and behavior) rather than its explicit type.
8. What is the difference between 'deep copy' and 'shallow copy' in Python?
💡 A deep copy recursively duplicates nested objects, while a shallow copy only copies the top-level structure.
9. What does 'strict mode' in JavaScript help with?
💡 Strict mode enforces stricter parsing and error handling, helping catch common coding mistakes.
10. What is 'currying' in JavaScript/functional programming?
💡 Currying transforms a function that takes multiple arguments into a sequence of functions, each taking one argument.
11. What is a 'Promise' in JavaScript used for?
💡 A Promise represents the eventual completion or failure of an asynchronous operation and its resulting value.
12. What is a 'closure' in JavaScript?
💡 A closure is a function that 'remembers' the variables from its enclosing scope, even after that scope has finished executing.
13. What is a Python 'lambda' function?
💡 A lambda function is a small, anonymous function defined inline using the 'lambda' keyword.
14. What does '*args' allow in a Python function?
💡 '*args' allows a function to accept any number of positional arguments.
15. What does 'GIL' stand for in Python?
💡 GIL stands for Global Interpreter Lock, a mutex that prevents multiple threads from executing Python bytecode simultaneously.
16. What does '**kwargs' allow in a Python function?
💡 '**kwargs' allows a function to accept any number of keyword arguments as a dictionary.
17. What is 'hoisting' in JavaScript?
💡 Hoisting is JavaScript's behavior of conceptually moving declarations to the top of their containing scope before code execution.
18. What does the 'spread operator' (...) do in JavaScript?
💡 The spread operator expands an iterable, like an array, into its individual elements.
19. What does 'async function' return in JavaScript?
💡 An async function always returns a Promise, even if the function itself doesn't explicitly return one.
20. What is 'prototypal inheritance' in JavaScript?
💡 In prototypal inheritance, objects inherit properties and methods directly from other objects through a prototype chain.