Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




concat() - FUNCTION


The concat() Function is used to join two Strings into one String.


Say, we have two Strings, Hello and World. And we want to join/concatenate them into one String, HelloWorld.


Let us solve it with the below example.


Example :



<html>
<body>  
<script>

	var x = "Hello"
	var y = "World"
    var z = x.concat(y)
	document.write(z)
    
</script>      
</body>
</html>


Output :



  HelloWorld

So, we have stored the String Hello in x.


var x = "Hello"

And, stored the String World in y.


var y = "World"

And used the + operator to join/concatenate Hello and World.


var z = x.concat(y)

And store the concatenated value in z.

java_Collections

But we cannot use the concat() function to join/concatenate a number and a String.


i.e. The below code will result into an error.


Example :



<html>
<body>  
<script>

	var x = 5
	var y = "World"
    var z = x.concat(y)
	document.write(z)
    
</script>      
</body>
</html>