I'm overweight & want to prevent type 2 diabetes. If I eat some junk food often but still lose & get to a healthy weight, is that okay, or can junk food itself cause diabetes even if I lose weight?

Junk food. Junk food won't cause diabetes it will cause you to exhibit the disease . The essential problem in diabetes is the bodies inability to handle sugar . The more sugar you eat the less it can handle and vice versa.
It depends... There are many types of "junk food" so this depends some on the type of junk food, but most of it contains corn, sugars in the form of high fructose corn syrup &/or is fried in "vegetable oil" from corn, soy or canola. These foods are gmo unless organic & until proven otherwise i consider gmo foods toxic/hazardous. Choose relatively healthy junk food- at least organic junk food! see my comment:.
It matters. It matters if there is fiber in the food and the amount of sugar. The reason is: no fiber and high sugar foods cause the production of high insulin- this could lead to Insulin resistance and diabetes. Aim for fresh fruits and vegetables, high in fiber. Choose these instead of junk foods. Look at the grams of fiber in what you eat, it slows the absorption of sugar into the blood. Try to exercise.
Eat right & exercise. Junk food, in & of itself, won't cause diabetes but in excess, will contribute empty calories to weight gain which will then increase risk. In other words, rare & occasional junk food isn't a problem but it's the main source of calories, then risk increases. But main concerns is weight. Best solution then is to eat right & exercise regularly to minimize risk.