A hundred JavaScript, Python, SQL, pandas and NumPy interview questions, each with its real output
Every snippet below was run before its answer was written. Each page gives the four options, the answer, and a reason for every wrong option.
JavaScript
- JavaScript Scope, Hoisting and Closures, what does console.log(x) print after let x = 'outer'?
- What does console.log(['a', 'b', 'c'].reduceRight((acc, x) => acc + x)) print? JavaScript Arrays and Iteration
- What does .then(v => console.log(v)) print? JavaScript Promises, async await and the Event Loop
- What does console.log('5' - 2) print? JavaScript Types, Coercion and Equality
- JavaScript this, Prototypes and Classes, what does console.log(Named.label()) print after const Named = class MyClass?
- What does console.log({ a: 1 } === { a: 1 }) print? JavaScript Objects, Destructuring and Immutability
- What does console.log(handle(new TimeoutError('late'))) print? JavaScript Errors, Control Flow and Sharp Edges
- What does console.log(obj.hasOwnProperty('a'), obj.hasOwnProperty('toString')) print? JavaScript this, Prototypes and Classes
- JavaScript Objects, Destructuring and Immutability, what does console.log(id) print after const response = { data: { user: { id: 7 } } }?
- What does console.log(5 << 2) print? JavaScript Numbers, Strings and Regular Expressions
- JavaScript Scope, Hoisting and Closures, what does console.log(x) print after let x = 'outer', sample question 11?
- What does console.log(JSON.stringify(rest)) print? JavaScript Arrays and Iteration
- What does console.log(trace.join(' ')) print? JavaScript Promises, async await and the Event Loop
- What does console.log(1 + 2 + 'a') print? JavaScript Types, Coercion and Equality
- JavaScript this, Prototypes and Classes, what does console.log(c.area()) print after function Shape() {}?
- What does setTimeout(() => console.log(trace.join(' ')), 0) print? JavaScript Promises, async await and the Event Loop
- What does console.log(e + 8) print? JavaScript Errors, Control Flow and Sharp Edges
- JavaScript this, Prototypes and Classes, what does console.log(Shape.count) print after class Shape?
- JavaScript Objects, Destructuring and Immutability, what does console.log(firstItem) print after const { list: [firstItem] } = { list: ['a', 'b'] }?
- What does console.log('Hello'.at(-1)) print? JavaScript Numbers, Strings and Regular Expressions
Python
- Python Scope, Functions and Closures, what does print(t()) print after def counter()?
- Python Lists, Tuples and Slicing, what does print(b) print after a = [3, 1, 2]?
- What does print(hello('Sam')) print? Python Iterators, Generators and Decorators
- What does print(a is b) print? Python Data Types, Numbers and Strings
- Python Classes, Objects and Special Methods, what does print(l.x, l.y) print after class Lazy?
- What does print(sorted(a | b)) print? Python Dictionaries, Sets and Comprehensions
- Python Mutability, References and Copying, what does print(data) print after def grow(lst)?
- Python Scope, Functions and Closures, what does print(data) print after def clear_it(container)?
- What does print(any([])) print? Python Lists, Tuples and Slicing
- Python Mutability, References and Copying, what does print(items) print after def add_item(lst)?
- Python Scope, Functions and Closures, what does print(a, c) print after def build(value, acc=[])?
- Python Lists, Tuples and Slicing, what does print(a) print after a = [[1, 2], [3, 4]]?
- Python Iterators, Generators and Decorators, what does print(ping.calls) print after def counted(func)?
- What does print(s.count('an')) print? Python Data Types, Numbers and Strings
- Python Classes, Objects and Special Methods, what does print(c.host, c.port) print after class Config?
- What does print(sorted(b - a)) print? Python Dictionaries, Sets and Comprehensions
- What does print(original['items']) print? Python Mutability, References and Copying
- What does print(greet(5) if False else greet('5')) print? Python Scope, Functions and Closures
- What does print(all([1, 2, 0])) print? Python Lists, Tuples and Slicing
- Python Mutability, References and Copying, what does print(b) print after a = [1, 2]?
SQL
- What does SELECT stations.label, shifts.label FROM stations CROSS JOIN shifts ... return? SQL Joins
- What does SELECT applicant FROM waitlist WHERE priority NOT IN (1, 2) AND ... return? SQL NULL, CASE and Set Operations
- What does SELECT city FROM temps WHERE ABS(change) > 1 ORDER BY city return? SQL Strings, Numbers and Type Conversion
- What does SELECT name FROM catalog WHERE price BETWEEN 10 AND 50 ORDER BY name return? SQL Selecting, Filtering and Sorting
- What does SELECT account, COUNT(*) FROM withdrawals WHERE amount >= 50 GROUP BY ... return? SQL Grouping and Aggregation
- What does SELECT school, grade_level, student, score, RANK() OVER (PARTITION BY ... return? SQL Window Functions
- What does SELECT * FROM bookings ORDER BY id return? SQL Data Modification and Constraints
- What does SELECT member, COUNT(*), COUNT(returned) FROM loans GROUP BY member ... return? SQL Grouping and Aggregation
- What does SELECT name, points, RANK() OVER (ORDER BY points DESC) AS rnk, ... return? SQL Window Functions
- What does SELECT * FROM parts ORDER BY sku return? SQL Data Modification and Constraints
- What does SELECT machines.tag, thresholds.label FROM machines JOIN thresholds ON ... return? SQL Joins
- What does SELECT product FROM filters WHERE category NOT IN ('A', 'B', NULL) return? SQL NULL, CASE and Set Operations
- What does SELECT q FROM queries WHERE q LIKE '1__\% sure' ESCAPE '\' return? SQL Strings, Numbers and Type Conversion
- What does SELECT id FROM codes WHERE (a = 1 OR a = 2) AND NOT b = 3 return? SQL Selecting, Filtering and Sorting
- What does SELECT event, SUM(revenue) FROM ticket_sales GROUP BY event ORDER BY ... return? SQL Grouping and Aggregation
- What does SELECT artist, track, play_count, DENSE_RANK() OVER (PARTITION BY ... return? SQL Window Functions
- What does SELECT * FROM books ORDER BY id return? SQL Data Modification and Constraints
- What does SELECT CASE WHEN points >= 60 THEN 'pass' ELSE 'fail' END AS result, ... return? SQL Grouping and Aggregation
- What does SELECT team, name, hire_date, ROW_NUMBER() OVER (PARTITION BY team ... return? SQL Window Functions
- What does SELECT dish FROM menu WHERE price > 10 ORDER BY dish return? SQL Data Modification and Constraints
pandas
- pandas Series, Index and dtypes, what does print(s.tolist()) print after s = pd.Series([1, True])?
- What does print(s.astype(int)) print? pandas Series, Index and dtypes
- What does print(s[s > 3].tolist()) print? pandas Series, Index and dtypes
- What does print(df[df['a'].isin([1, 4])]['b'].tolist()) print? pandas Selecting with loc, iloc and Masks
- What does print(df.iloc[-1]['a']) print? pandas Selecting with loc, iloc and Masks
- pandas Missing Data, NaN and NA, what does print(s.sum()) print after s = pd.Series([1, 2, None])?
- pandas Missing Data, NaN and NA, what does print(s.tolist()) print after s = pd.Series([1, None, 3])?
- What does print((a + b).tolist()) print? pandas Missing Data, NaN and NA
- What does print(df.groupby('k')['v'].sum().index.tolist()) print? pandas GroupBy and Aggregation
- What does print(df.groupby('k')['v'].agg(lambda s: (s ** 2).sum()).to_dict()) print? pandas GroupBy and Aggregation
- pandas Merge, Join and Concat, what does print(merged.shape) print after left = pd.DataFrame({'k': [1, 1, 2], 'a': ['a1', 'a2', 'a3']})?
- What does print(list(combined.columns)) print? pandas Merge, Join and Concat
- What does print(type(combined).__name__, combined.tolist()) print? pandas Merge, Join and Concat
- What does print(list(melted.columns)) print? pandas Reshaping, Pivot and Melt
- pandas Reshaping, Pivot and Melt, what does print(sorted_df.shape) print after df = pd.DataFrame({'a': [1, 1, 2], 'b': [3, 1, 2], 'orig': [0, 1, 2]})?
- What does print(df['b'].tolist()) print? pandas Copy-on-Write, Views and Assignment
- What does print(resultat, df['a'].tolist()) print? pandas Copy-on-Write, Views and Assignment
- What does print(df['a'].tolist()) print? pandas Copy-on-Write, Views and Assignment
- What does print(s.str.startswith('a').tolist()) print? pandas Strings, Dates and apply
- pandas Strings, Dates and apply, what does print(out.shape) print after df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})?
NumPy
- NumPy Arrays, dtypes and Scalars, what does print(a.dtype) print after a = np.array([1, 2.5, True])?
- NumPy Arrays, dtypes and Scalars, what does print(a) print after a = [np.int64(1), np.int64(2)]?
- NumPy Arrays, dtypes and Scalars, what does print(b.dtype) print after a = np.array([1, 2, 3], dtype=np.float32)?
- What does print(m[1, 2]) print? NumPy Indexing, Slicing and Masks
- NumPy Indexing, Slicing and Masks, what does print(a.tolist()) print after a = np.array([10, 20, 30, 40, 50])?
- NumPy Indexing, Slicing and Masks, what does print(a.tolist()) print after a = np.array([10, 20, 30, 40, 50]), sample question 6?
- What does print((a + b).tolist()) print? NumPy Broadcasting and Shapes
- What does print(a[np.newaxis, :].shape) print? NumPy Broadcasting and Shapes
- What does print(b.base is None) print? NumPy Views, Copies and Reshape
- What does print(a.reshape(4, -1).shape) print? NumPy Views, Copies and Reshape
- What does print(a.sum(axis=1).tolist()) print? NumPy Reductions and the axis Argument
- What does print(h.cumsum(axis=1).tolist()) print? NumPy Reductions and the axis Argument
- NumPy Reductions and the axis Argument, what does print(b.argmax()) print after b = np.array([[1, 2], [3, 4], [5, 6]])?
- NumPy NaN, Overflow and Type Promotion, what does print(a.max()) print after a = np.array([1.0, np.nan, 3.0])?
- What does print((a + 127).tolist()) print? NumPy NaN, Overflow and Type Promotion
- What does print(r, a.tolist()) print? NumPy Sorting, Searching and unique
- What does print(np.sort(a, axis=1).tolist()) print? NumPy Sorting, Searching and unique
- What does print(np.argsort(a, axis=1).tolist()) print? NumPy Sorting, Searching and unique
- What does print(np.split(a, 3)) print? NumPy Stacking, Splitting and Concatenation
- What does print(np.concatenate([a, b]).tolist()) print? NumPy Stacking, Splitting and Concatenation
Did this save you a lookup? Buy me a coffee on Ko-fi.