Search Unity

Why the syntax difference?

Discussion in 'Scripting' started by edplane, Mar 15, 2011.

  1. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    Hi, I've been programming in Unity for about a year, but I recently started learning web design and JavaScript. What I want to know is why is the syntax different from Unity's JS and web JS? For example, functions in Unity JS must be capitalized, but in the web JS they must be lower cased. And why is it that in Unity JS variables can be declared outside or inside a function, but in web JS, they must be inside? Though, I would assume you can declare them outside of a function in web JS if you give a special perimeter (like in C).

    For instance, here would be an example of Unity JS:
    Code (csharp):
    1. var num = 1;
    2. Function Start(){
    3. Debug.log("Stored var is:" + 1);
    4. }
    While in web JS, something similar (where the function is called in HTML)might be:
    Code (csharp):
    1. function writeDoc() {
    2. var num =1;
    3. document.write("The stored var is:" +1);
    4. }
    This is just a general question, not really relevant, but I want to understand the language better so if anyone has an answer, yay! :D
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Javascript in Unity isn't actually Javascript at all, so it's best not to think of it that way. It's mostly like JScript.NET, so read this.

    --Eric