Sure!

One nice feature that CodePen has is that it can teach you about JavaScript errors as you write.

You might also use the console to log exceptions and variables.

Or, you might go more full-on and use a JavaScript testing framework. Here's an example that uses Mocha and Chai:

See the Pen Mocha / Chai in the Browser by Chris Coyier (@chriscoyier) on CodePen.

With a setup like this, here's some options:

  • Use Presentation Mode project the Pen and work through the code showing how the testing works.
  • Set up a failing Pen, then use Collab Mode to invite a student or interviewee in and have them fix the JavaScript so the test passes.
  • Email a failing Pen to your students and have them fork and fix it as homework.