How to prevent parameters created with Scripted Pipeline to replace the ones set on the UI?

Solution for How to prevent parameters created with Scripted Pipeline to replace the ones set on the UI?
is Given Below:

With Jenkins Declarative Pipeline syntax, in the parameters block, the behavior of the parameters is like so:

  1. If the defaultValue of the parameter is customized in the Jenkins UI, it will take precedence over the defaultValue in the Jenkinsfile.
  2. It will not remove the parameters which are not defined in code but are set in the UI.

However, if I set any parameters using properties in a scripted pipeline, the defaultValue set in the UI gets replaced (1) and parameters not set gets deleted (2).