20 difficult programming questions and answers designed for true quiz masters on Python and JavaScript.
1. 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.
2. What is a 'Promise' in JavaScript used for?
💡 A Promise represents the eventual completion or failure of an asynchronous operation and its resulting value.
3. 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.
4. What is 'prototypal inheritance' in JavaScript?
💡 In prototypal inheritance, objects inherit properties and methods directly from other objects through a prototype chain.
5. What is 'hoisting' in JavaScript?
💡 Hoisting is JavaScript's behavior of conceptually moving declarations to the top of their containing scope before code execution.
6. What is 'list comprehension' in Python used for?
💡 List comprehension provides a concise syntax for creating lists based on existing iterables.
7. What does 'async function' return in JavaScript?
💡 An async function always returns a Promise, even if the function itself doesn't explicitly return one.
8. What does '**kwargs' allow in a Python function?
💡 '**kwargs' allows a function to accept any number of keyword arguments as a dictionary.
9. What does the 'spread operator' (...) do in JavaScript?
💡 The spread operator expands an iterable, like an array, into its individual elements.
10. What does 'strict mode' in JavaScript help with?
💡 Strict mode enforces stricter parsing and error handling, helping catch common coding mistakes.
11. What is a 'decorator' in Python?
💡 A decorator wraps a function to modify or extend its behavior without changing its actual code.
12. What is a Python 'lambda' function?
💡 A lambda function is a small, anonymous function defined inline using the 'lambda' keyword.
13. 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.
14. What is 'currying' in JavaScript/functional programming?
💡 Currying transforms a function that takes multiple arguments into a sequence of functions, each taking one argument.
15. 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.
16. 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.
17. What does '*args' allow in a Python function?
💡 '*args' allows a function to accept any number of positional arguments.
18. What does 'GIL' stand for in Python?
💡 GIL stands for Global Interpreter Lock, a mutex that prevents multiple threads from executing Python bytecode simultaneously.
19. What is 'duck typing' in Python?
💡 Duck typing focuses on what an object can do (its methods and behavior) rather than its explicit type.
20. 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.