Im wondering how i create a cookie?

i was reading an article on javascript and it said i should store a variable in a cookie. Though ive known about cookies for some time now, i have never looked into how they are created and how exactly they work.

also. would anyone be so kind as to tell me what security issues go along with cookies? for example... passwords stored in cookies.