Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Why is it not necessary to create a variable by type in JavaScript?

 
Greenhorn
Posts: 19
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am taking a course to learn JavaScript. Although it is not my first programming language (I have programmed in Java and yes I understand that the two languages are different), I had a question about variables.

Variables in Java are created by type (i.e., int, long, char etc.)

Question One:

Is it necessary to establish the variable type before creating a variable in JavaScript?

Follow Up to Question One:

OR am I confused as to JavaScript variables are created?
 
Marshal
Posts: 67424
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll answer in reverse order:

Sally Jenkins wrote:OR am I confused as to JavaScript variables are created?


Yes.

Is it necessary to establish the variable type before creating a variable in JavaScript?


As this is homework, I'll turn the question around. Given the answer above, what do you think?
 
Sally Jenkins
Greenhorn
Posts: 19
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I guess I was a bit unclear in my post. This question was not a request to help me complete a particular homework assignment. My homework assignment is complete.

I was told that I should post questions online so that I could acquire a deeper understanding of JavaScript as a whole.

It was my sincere hope that someone might be willing to help me learn more beyond my textbook, class assignments or simple online videos.

Any takers?
 
Bear Bibeault
Marshal
Posts: 67424
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's cool. So if you're homework is complete, what specifically do you not grok yet?

TLDR: in JavaScript variables are not typed, values are typed. And any variable can hold any value.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic