Lil help translating c++ to javascript

I have this code from the Unite security video:

int key;

int _val;
int val
{
    get { return _val ^ key; }
    set { _val = value ^ key; }
}

void Awake ()
{
    key = Random.Range(0, 2147483647);
}

But I am not sure how I translate this to my javascript:

    int val
    {
        get { return _val ^ key; }
        set { _val = value ^ key; }
    }

You’re talking about C#, not C++. In Unityscript it would be:

var key : int;
var _val : int;
function get val () : int { return _val ^ key; }
function set val (value : int) { _val = value ^ key; }

function Awake () {
	key = Random.Range(0, 2147483647);
}

That’s a C# property, which AFAIK, don’t exist in Javascript. Break the get and set into two functions:

function getVal() : int
{
  return _val ^ key;
}

function setVal(int value)
{
  _val = value ^ key;
}

Whenever the variable val is set in C#, use setVal, and getVal everywhere else val is referred to.