Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide a variable value in JavaScript?

I am currently working on a JavaScript project and know that JavaScript source code is accessible through the browser. In the code, I have a variable that stores a secret string that is used by the program. However, I do not want others to view the source code and find out the value of this variable. Is there a way to hide the value of a variable? Or is it possible to change the variable value after? For instance, change the actual source code to set the variable to a different value? This variable is only used the first time an image is loaded so it would be okay to remove it altogether if that is possible.

like image 402
user3647894 Avatar asked Nov 10 '22 18:11

user3647894


1 Answers

You cannot hide JavaScript content from a programmer. They can always open the developer console and get all your variables.

What's worse, they can use said console to directly bypass any JavaScript validation, so it cannot be your primary security.

If it is something you must hide or secure against, you must look into a server side solution.

like image 163
Nelson Avatar answered Nov 14 '22 22:11

Nelson