CSE 154 Examples

String Concatenation

Description :

Like Java and Python, you can concatenate Strings in Javascript as well.
If we have two strings "Hello " and "World", we can concatenate them using the + operator directly. This can also be acheived using the concat(stringInTheMiddle, stringToBeJoined) method. Note the concat method returns a new string and the original string remains unchanged

Syntax : let added_string = original_string1 + original_string2;

let added_string = original_string.concat(middle_string, original_string2);

Examples :

				
					let firstWord = "Hello ";
					let secondWord = "World";
				
					firstWord + secondWord =  ?? 
			
				
					let firstWord = "Hello ";
					let secondWord = "World!";
					let result = firstWord.concat(" ", secondWord);
				
					result =  ?? 
			
				
					let firstWord = "Hello ";
					let secondWord = "World!";
					let result = firstWord.concat(" :) ", secondWord);
				
					result =  ??