How to detect a collision between two certain objects

In my game, I want it so then if there are two certain objects colliding, I can tell my script to do something. I know about OnTriggerEnter and OnCollisionEnter but that is with all colliders. I need it so then I can choose what colliders something will happen with. And if you can, I will need it in JavaScript.

Usually tags are used for this purpose. If the moving object is a rigidbody, use OnCollisionEnter:

function OnCollisionEnter(col: Collision){
  if (col.gameObject.tag == "Wall"){
    // this rigidbody collided with an object tagged Wall

Triggers are more suitable for things that you may enter or pass through, like portals, pickup items etc. Usually the moving object is a rigidbody or CharacterController, and the trigger is static. If you want the trigger to be the moving object, add a kinematic rigidbody to it or nothing will happen.

function OnTriggerEnter(other: Collider){
  if (other.tag == "Wall"){
    // this rigidbody or CharacterController entered a trigger tagged Wall