Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible somehow to prevent users from being able to change JavaScript variables, trough the address bar or with programs like FireBug?

share|improve this question
Some insight into what your goal is may help us help you find a tamper-proof solution. I can tell you right now that you will need some help from PHP, ASP or other server-side scripting. – Paul Lammertsma Apr 19 '10 at 16:27
up vote 10 down vote accepted

JavaScript is raw source code being interpreted on the client machine, so the short answer is no. The best you could perform as much work as you can on the server. Any JavaScript code you push to the client can be tampered with by the client.

share|improve this answer

This is one of those questions that pretty much begs the response "What is your ultimate goal?"

As stated by others, no, you can't. JavaScript is client side so entirely in the hands of the client, not you.

Obfuscation, as heavyd mentions, could be useful, but it's certainly not a secure/sure-fire way to prevent it.

If this is something you need for security reasons, then the answer is likely that it shouldn't be done with client side JavaScript in the first place.

share|improve this answer

You could create private variables and use an accessor method to get at them

var mySingleton = function(){

    /* here are my private variables and methods */

    var privateVariable = 'something private';

    function showPrivate(){



    /* public variables and methods (which can access private variables and methods ) */

    return {




        publicVar:'the public can see this!'



var single = mySingleton();

single.publicMethod();  // logs 'something private'

console.log(single.publicVar); // logs 'the public can see this!'
share|improve this answer

No, but you can obfuscate your code to make it difficult to read and reverse engineer.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .