JavaScript How to Add Nonce in JavaScript? Nonce is a random and unique value used to enhance defenses against malicious script injection attacks, especially when used in conjunction with Content Security Policy (CSP) and other security measures.