WordPress theme’s Functions file (functions.php) is the main WordPress theme file. The file allows theme developers to change the default behaviours of WordPress. WordPress developers normally add PHP functions (methods) to that file by using custom hooks and actions to add new features or update existing methods behaviour of theme or plugins.
Note: Make sure not to edit or change a function.php file in the main theme rather create a child theme and add the function.php file into it and then add the desired code so that your code will not be overwritten during updating theme.
WordPress codex site defines Function file as:
The function file behaves like a WordPress Plugin, adding features and functionality to a WordPress site through PHP code. You can use it to call native PHP functions, WordPress functions, or to define your own functions.
You can place your custom PHP code directly into your child theme function.php, or simply use a plugin such as the Code Snippets plugin (recommended) to manage your custom snippets.
Difference between a plugin and a functions.php file
A WordPress Plugin and a theme’s Functions file are both same in a broad sense. The main difference between the two is that the functions file applies only to the existing activated theme while the plugin applies to all themes.
The WordPress plugin is independent of your WordPress theme and will work no matter what theme you are using. It’s a common practice that the theme’s functions.php file uses WordPress Hooks, the huge collection of WordPress actions and filters that can change almost anything that WordPress does.