Each question has a short model answer. In a real interview, add an example from your own code wherever you can.

Python

  1. What is the difference between a list and a tuple? Lists are mutable (you can change them); tuples are immutable. Tuples can be used as dictionary keys if their contents are hashable, and are slightly lighter in memory.
  2. What is the difference between is and ==? == checks whether two values are equal; is checks whether two names point to the exact same object in memory.
  3. Why is def add(item, items=[]) a bug? Default arguments are created once, when the function is defined, so the same list is shared across calls. Use items=None and create a new list inside the function.
  4. What are args and *kwargs? args collects extra positional arguments into a tuple; *kwargs collects extra keyword arguments into a dictionary.
  5. What is a decorator? A function that takes another function and returns a modified version of it, used for logging, timing, caching, or access checks. Applied with @decorator_name.
  6. What is a generator? A function that uses yield to produce values one at a time, only when asked. It saves memory when working with large or infinite sequences.
  7. Shallow copy vs deep copy? A shallow copy creates a new outer object but shares the nested objects; a deep copy (copy.deepcopy) duplicates everything, including nested objects.
  8. What is the GIL? The Global Interpreter Lock in standard CPython lets only one thread run Python bytecode at a time. Threads still help for I/O-bound work; for CPU-bound work, use multiprocessing. (Newer Python versions offer an optional free-threaded build.)
  9. List comprehension vs generator expression? [x*x for x in nums] builds the whole list in memory; (x*x for x in nums) produces values lazily, one at a time.
  10. How does a dictionary look up keys so fast? It is a hash table: the key's hash points almost directly to its slot, giving average O(1) lookups.
  11. What do else and finally do in a try block? else runs only if no exception was raised; finally always runs, which makes it the place for cleanup.
  12. What is the difference between __init__ and __new__? __new__ creates the object; __init__ initializes it after creation. You rarely need to override __new__.

JavaScript

  1. What is the difference between var, let, and const? var is function-scoped and hoisted with the value undefined. let and const are block-scoped; const cannot be reassigned, though an object it holds can still be changed.
  2. == vs ===? == converts types before comparing (0 == "" is true); === compares value and type (0 === "" is false). Use === by default.
  3. What is hoisting? Declarations are moved to the top of their scope before code runs. Function declarations are fully hoisted; let and const are hoisted but cannot be used before their line (the temporal dead zone).
  4. What is a closure? A function that remembers the variables from the scope where it was created, even after that outer function has finished. Used for private state and function factories.
  5. How does this work? It depends on how a function is called: the object before the dot for methods, the new object with new, and undefined (in strict mode) for a plain call. Arrow functions take this from the surrounding scope.