In the code below I want to hide the contents of the key(speaker) key being viewed by browser console.
var App_Version = 1;
var App_id = 35;
var Speaker = "password";
In the code below I want to hide the contents of the key(speaker) key being viewed by browser console.
var App_Version = 1;
var App_id = 35;
var Speaker = "password";
If var Speaker = "password";
is hardcoded somewhere in your client code, you are out of luck. See Password encryption at client side, and Howto hide Credentials in a pure Javascript HTML Web App and Is it worth hashing passwords on the client side because everyone will say not to hide/obfuscate a password on the client-side.
However, If you really, really just want to remove the password altogether from your client code, then use a server-side script to "proxy" your AJAX request and silently add the password as a POST parameter (for example) in transit to the true destination. See Angular REST API security
If you are adamant about using some kind of crypto on the client-side, I found angularjs-crypto which is an "AngularJS module for decryption/encryption of JSON in HTTP requests/responses". It is based on crypto-js. I still strongly against taking a hardcoded password and encrypting it on the client-side, however.
Well you can't "hide" javascript.
You can encrypt it with an obfuscator but most people can decrypt it using a beautyfier. However check this out:
There is no way in Javascript to hide the contents of a variable without unsetting the variable, which is of no use to you if you need to reference whatever that value was later. A few options to choose from, depending on exactly what you need would be this:
Hashing the value
You could has the value with MD5 or SHA. This way the user doesn't know what the value is but you can still send it off to the server and store it that way
Store the value on the server
You could store the value on the server and reference it with some sort of key. That way the user never sees the actual value, they are just checking the server to see if the value they have matches what the server has.
If this is a password that is being generated and we never want the user to see it, your best bet is to handle all of that on there server, this way there is no chance the user will ever even have the value on the client side.
Javascript code is considered temperable so you can't really hide a password in your code. The best practice is to use oAuth2 which uses temporary tokens(to defer from passwortds) that in conjunction with things like CSRF can make you client side code more secure. Here's one library that can help you do that in JS. It does require that on your server side when accessing resources you need to validate that token (preferably on every call). To some it up if you need to store a password on the browser in order to log into a server - don't. Let the user log in and the afterwards use the token issues by the server or use a third party login and use the token you got from the third party authentication server.
Nice question even I had came across such situation where my API key and authentication token was visible at client side.Obfuscating a client side Javascript file is best option. You can use UglifyJS for obfuscating the clientside code. And also there must be permissions on the server side for creating and deleting objects.
although it's not fully clear from the small code provided, protecting it from the browsers console is straight forward IF we are only talking about someone console.logging the value (as your question seems to hint).
you can put it inside a closure, something like a revealing/modular pattern:
var app = (function () {
var Speaker = "something";
// only available on app declaration as the function is immediately called
return // some object/function protecting the speaker value
})();
console.log(Speaker); // gives an error
console.log(app.Speaker); // gives an error
This of course only stops someone using basic dev tools like console.log, it wont stop someone adding breakpoints. the nature of javascript I'm afraid
Well you can't "hide" javascript. but you can encrypt them using OBFUSCATOR and other tools