When you open a file, the file manager performs the default action for that file type.
For example, opening a music file will play it with the default music playing application, opening a text file will allow you to read and edit it in a text editor, and opening an image file will display the image.
The file manager checks the contents of a file to determine the type of a file. If the first lines do not determine the type of the file, then the file manager checks the file extension.
If you open an executable text file, that is, one that Nautilus considers can be run as a program, then you will be asked what you want to do: run it, or display it in a text editor. You can modify this behaviour in the File Management preferences.