Foundations

Keep the Old Status

Keep the Old Status

Sometimes you need both the old value and the new value. Save the old value before you reassign the changing variable.

Your task: A page starts with currentStatus set to "draft". Store that original value in previousStatus, change currentStatus to "published", then log both statuses.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Keep the Old Status

Sometimes you need both the old value and the new value. Save the old value before you reassign the changing variable.

Your task: A page starts with currentStatus set to "draft". Store that original value in previousStatus, change currentStatus to "published", then log both statuses.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.