I have made the html5 game, that users sometime may try to alter to get better highscores.
How can I count in the begin(and runtime) of game the hash of whole JavaScript game ( made with Construct2) so that I can compare if there was any changes runtime done by user.
Game is running inside iframe if it matters anything and sends highscrores after the game.
As said in my comment, hashing your source it's not an efficient anti-hack.
The strongest way to prevent cheating is to run your engine server-side, and validate each action with a predictive client/authoritative server strategy.
Predictive client
The client engine behave as no server is involved, sending data (Eg.) only when score changes along with some additional information (Eg. gametime, position, player state etc etc). The client receive a unique token stored server side on each game session to identify it.
Authoritative server
The server, once received the score and the additional information, can run a validation against those data, eg:
Once validation on server side happened, you can reconciliate the game state or invalidate the game by token once finished.