In linguistics, a term for the use of multiple languages or dialects in one utterance. Whereas borrowing involves no shift in pronunciation or even modification of a foreign word or phrase to better fit the phonotactic constraints of the language it is borrowed into, code-switching involves a full phonetic shift as well as adherence to certain social and grammatical constraints, discussed below.
Obviously, there is little value to code-switching in conversation with someone who doesn't know the languages being alternated, but code-switching is an important aspect of language use among bilingual speakers. It can be used to fill lexical gaps --- words that are not known in one language can be replaced with synonyms from another --- or in conveying ideas foreign to one language --- for example, information that is culturally specific, like names of certain food items. Even non-native speakers of a language may find themselves code-switching or borrowing for this latter purpose, and loanword formation may ensue if a code-switching or borrowing proves particularly useful and spreads into common use.
Some uses of code-switching are less universal: for members of bilingual linguistic minority groups, code-switching can be a way of marking the distinctions between two languages: if this is the case, the two may also be associated with separate social, economic, and political worlds. Borrowing tends to blur such distinctions along with phonetic differences. In societies where bilingualism is rare, code-switching most often takes place among family members or close friends. As such, it can be used as a sign of intimacy or to convey secrets. Although this last use is rare, many monolinguals in the presence of code-switching bilinguals nonetheless suspect they're being talked about. Personally, I might code-switch for secrecy like I might whisper in monolingual conversation, if I don't want people listening in on me, but it's just as impolite to code-switch about someone as it is to whisper secrets about them right under their nose. Most bilinguals will agree with me when I say I code-switch primarily for convenience, without really thinking about it.
As with borrowing, there are syntactic constraints on code-switching. These are the subject of intense study and debate. For instance, most researchers agree that it is almost never grammatical to code-switch within a word. There are exceptions to this rule, but they are rare. Similarly, many theories hypothesize that the syntax of an utterance must match the language of the vocabulary being used: code-switching is possible when, for example, the word order of a sentence or noun or verb phrase is the same across the two languages being alternated. Switches rarely occur mid-phrase: for example, modifiers generally match the language of the noun or verb they are associated with.
On a related note, there appears to be a hierarchy of loanability (this might be a more appropriate topic for the borrowing writeup; I'm not sure). Based on studies of loanwords in various languages, nouns are far more likely to be code-switched or borrowed than any other grammatical category. Verbs or adjectives come next, depending on the language in question, and function words like prepositions and pronouns are last of all. This hierarchy is similar to the idea of open and closed categories in the study of language change: the former include nouns, verbs, and adjectives, which tend to change most rapidly, and the latter include pronouns, prepositions, and conjunctions.