If you ever want to publish to mobile platforms, you will need #pragma strict. If you are following tutorials that don’t work with #pragma strict, it’s time to follow different tutorials. And If those tutorials are in C#, it’s time to learn C#.
Ah, who am I kidding, it’s time to learn C#. 
Here’s the deal: UnityScript (what they call JavaScript) has a feature where it doesn’t necessarily need to know the type of a particular variable right when it’s declared.
var x;
x = "foo ";
Debug.Log(x.Trim());
x = 23;
Debug.Log(Mathf.Max(x, 10) );
UnityScript will understand that x is a string for line 2, and it will be able to call the string’s .Trim() function. And come line 4, it knows that x is now an integer, so it can allow it as a parameter in Mathf.Max.
Nice feature, right? Very newbie-friendly? Well, here’s the problem: Code that does that is basically impossible to compile, in the traditional sense of the word “compile”. When you type x.Trim() on an object that it knows at compile-time is a string, the compiler can have that function point directly to the bit of code that executes that function. When you type x.Trim() and it doesn’t know at compile time what x is going to be, it has to compile this as a bit of code that says, basically, x.WhateverThisIsFindTheFunctionNamed(“Trim”);
So when you stick a string into x, it has to do a little tiny bit of “compilation” to figure out that x is a string, and where that class’s function named “Trim” is, and it has to do that on the device, as it’s running. It’s a clever strategy, don’t get me wrong. BUT…
-
It’s slow. Searching for the function by name takes much longer than just pointing it to the function that it knows ahead of time.
-
Compiling code on the device is a big no-no with Apple. (I think Android Play and the Windows Store have similar policies, but don’t quote me on that.) It has the potential to be wildly insecure.
Basically, all #pragma strict does is turn off that feature of the language. The speed is a factor in the recommendation to use #pragma strict. But I never saw #pragma strict in the wild until Unity started compiling to iPhones. Being able to publish to iPhone is the main reason to use #pragma strict.
P.S. There's one subtlety that might confuse you if you start experimenting, and its name is *type inference*. This code will not run with #pragma strict:
```
var x;
x = "foo";
```
But this will run just fine (and is valid in C#, even!):
```
var x = "foo";
```
The first is *dynamic typed*. Once it gets to the "var x;" line, it knows nothing about x, it just makes x a bland object and marks it as "I'll figure it out later", and it's the figuring out later that causes the problems.
The second is uses *type inference*. By looking at the line as a whole, the compiler can figure out that by "var", what you really meant was "string". If, in the next line, you set x = 23, it will then give you an error, because it's already decided that x is a string.
Type inference is really useful if you're dealing with certain advanced data types, like generics:
```
//with type inference
var someDictionary = new Dictionary<string, SomeDataTypeWithALongName>();
//without it
Dictionary<string, SomeDataTypeWithALongName> someDictionary = new Dictionary<string, SomeDataTypeWithALongName>();
```