• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JS variable vs Scope variable

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just came to know that Javascript variable are global, can be accessible from any file (JSP, HTML and Servlet).

Now I am thinking why we worry about scope and all, as soon as you get the data, store them into JS variable and then use them whenever you want...

Okay one drawback comes in mind is security, is that really a drawback???

Any other drawbacks???

Thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JavaScript variable only lives on that page. It is not shared between pages unless you have parent/child(pop up windows or frames) references.

Not sure what you are talking about. You are making it sound like JavaScript can talk to the back end through variable scope.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
I just came to know that Javascript variable are global, can be accessible from any file (JSP, HTML and Servlet).


Completely incorrect. Javascript variables don't even exist when the JSP and Servlets are executing.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I pointed you to this article in another post. You really need to read it.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric Pascarello:
A JavaScript variable only lives on that page. It is not shared between pages unless you have parent/child(pop up windows or frames) references.

Not sure what you are talking about. You are making it sound like JavaScript can talk to the back end through variable scope.

Eric


Actually, my project has lots of frame so I got this wrong impression.

Bear, thanks for the link, I will read it for sure as I get some time from the project.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic