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 trialAdam Castillo
7,585 PointsDo you ever have to declare a datatype in JavaScript like you have to in Java?
Does the browser automatically recognize data types?
6 Answers
Stan Zapalikov
1,915 PointsNo, JavaScript is a weakly typed language.
Adam Castillo
7,585 PointsOk, thanks Stan.
Landon Sanders
1,262 PointsNo, Javascript is not strongly typed.
virus200
6,583 PointsThis 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.
tkati
4,703 PointsSome 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
2,466 PointsJAVA 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.