Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Working With Numbers Numbers

Do you ever have to declare a datatype in JavaScript like you have to in Java?

Does the browser automatically recognize data types?

6 Answers

No, JavaScript is a weakly typed language.

Ok, thanks Stan.

No, Javascript is not strongly typed.

virus200
virus200
6,583 Points

This was one of the first things I noticed starting the JS section since I have done some minor Java before. I was surprised you don't have to declare datatypes.

Some side notes: Being strongly typed and weakly type I'm pretty sure doesn't have to do with declaration of type. It has more to do if it can be changed. Dynamic vs static typed I think has to do more with when it can be changed or takes effect (compiler or run time). Not declaring a type doesn't mean it doesn't have a type. you'll still use typeof and === . == and === are both used in javascript, but the === also checks the type in addition to the value.

harman singh
harman singh
2,466 Points

JAVA SCRIPT JUST SHARED A SAME NAME AS JAVA BUT IN JAVA DATATYPES ARE DECLARED BECAUSE JAVA IS OBJECT ORIENTED AND THE CONCEPT BEHIND OOPS IS ENCAPSULATION AND INHERITANCE SO EACH VARIABLE HAS A DATA TYPE OF CLASS OR BELONGS TO CLASS . BUT IN JAVA SCRIPT ITS IS MORE WEB BASED LANGUAGE SO HERE DATATYPE IS NO NEED AND BROWSER HAS IN BUILT COMPILER TO COMPILE AND RUN CODE INTO HTML.