Debugging and testing JavaScript code

Debugging and testing are essential parts of the software development process. JavaScript provides several tools for debugging and testing code, including the Chrome DevTools debugger and the Jest testing framework. The Chrome DevTools debugger allows us to step through our code and inspect variables and objects at runtime. Jest is a popular testing framework that provides a simple and intuitive API for writing tests and assertions.

 // Chrome DevTools debugger example
function multiply(x, y) {
  return x * y;
}

const result = multiply(2, 3);
console.log(result);

// Add a breakpoint on the next line to pause execution
console.log('Execution paused here');

// Jest testing framework example
function sum(x, y) {
  return x + y;
}

test('sum function', () => {
  expect(sum(2, 3)).toBe(5);
  expect(sum(-1, 1)).toBe(0);
});