Best way to insert a js script in the header with custom fields and CPT

There was two problems with my code. The first one was I didn’t use esc_textarea(), but when i used it, the problem didn’t go away, so I check for the funcion that stores in database the text given in the text area and I found that; as all the other fields in my CPT are text fields, I was sanitizing them with sanitize_text_field() function, and that was removing the HTML tags. I remove sanitize_text_field() function from the text area variable before using it in update_post_meta(), and now all works.