The nonce parameter seems to be optional for transactions. Its goal is to protect from replay attacks. In that case, why is it optional, and what happens if it's not provided? It leaves the particular transaction prone to replay attacks?
If not provided then the nonce will be read from account's state on the blockchain (it is part of the blockchain state).
However, it can sometimes be useful to specify it explicitly. It might be useful, for example, if you need to re-send a transaction with a higher gas price if the first one is not being mined. If you send it again with the same nonce it will (may) over-write the first one.
So, the nonce does appear in all transactions whether you specify it or not, and it does protect against replay.
The nonce is not optional. To be valid, a transaction must provide a nonce.
The nonce that you need to supply for the next transaction can usually be calculated by looking at the blockchain. Most wallets and other software that makes transactions will do this for you behind the scenes, so you don't need to supply the nonce yourself manually, unless you have unconfirmed transactions that the software you are using does not know about.
There is a plan to allow users to define their own schemes for signing transactions. If and when this is implemented, it will be possible to dispense with the nonce altogether if you don't need replay protection, or use a different system that better fits your needs.
what happens if it's not provided?
The nonce parameter gets incremented every time((Like an Identity column in SQL) when transaction happens and its not mandatory for you to set.
Optionally you can also set nonce for a transaction and there is a bonus answer below from reddit.
To proactively answer your next question.
What happens if I submit a transaction with a nonce that has already been transacted?
It will be rejected by the network What happens if I submit a nonce that's higher than the correct next nonce to use?
The transaction will get stored in the mempool of the nodes in a pending state. It will remain in the mempool of the node until transactions with all nonces between the last valid incremental nonce for the account and the transaction stored in the mempool have been transacted to the network, and then the transaction will be executed as normal. It's possible that the nodes eventually drop your transaction out of the mempool if it's been waiting there for too long