Make two vocabularies with some terms, Pets (dog, cat) and Fruits (apple, orange). Add the Pets taxonomy term field to the Page type.
Create a node programmatically:
use Drupal\node\Entity\Node;
$node = Node::create([
'type' => 'page',
'title' => 'Created page',
'field_pets' =>[3], // tid 3 is apple, which should not be allowed in Pets
]);
$node->save();
This happens:

So in view mode, it appears that assigning a fruit to the Pets field has been successful. In edit mode, there are no terms assigned.
I were expecting to get a warning about trying to assign an impossible term id to a term field.
Comments
Comment #2
cilefen commentedComment #5
interdruper commentedSince this use case is only programmatic, params must be checked previously by the programmer: