1. Code is copyrighted automatically
In most countries, code is protected by copyright the moment you write it, even a short script. No registration or notice is needed.
By default, that means others generally cannot copy, modify, or redistribute it without your permission.
Code published without a license is not free for others to reuse.
(They can generally run a copy they already have, but copying it, changing it, or sharing it requires your permission.)
2. A license tells people what they may do
- use your code
- modify it
- credit you
- use it commercially
- share changes under the same terms (or not)
3. What about trivial scripts?
Very short snippets may be too simple to qualify for copyright, and the rules vary by country. Since it is hard to know where that line falls, adding a license anyway removes the doubt and makes your intent clear.