Facebook Pixel

Why should I avoid var?

var can lead to unexpected behavior due to function scope and hoisting.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in What Is the Difference Between var, let, and const?

In modern JavaScript, let and const are generally preferred over var.

The variable reference cannot be reassigned, although object contents may still be modified.

No. var is function scoped.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.