DONATE  
MENU
PHP
CSS
JSON
HTML
JAVASCRIPT
AJAX
MYSQL

JavaScript Tutorials

INTRODUCTION

» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls

CONDITIONAL TESTING

» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement

LOOPS

» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop

FUNCTIONS

» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions

ARRAYS

» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays

OBJECTS

» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword

AJAX

» Introduction to AJAX

JSON

» Introduction to JSON

JAVASCRIPT DATES

» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)

MATH OBJECT

» Math Object

» Math Methods

HTML / JS DOM

» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events

MISCELLANEOUS

» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript

JAVASCRIPT EXAMPLES

» JavaScript Calculator

.. » JavaScript » Introduction » JS Expressions & Concatenation
Share Tweet WhatsApp

JS Expressions & Concatenation

A JavaScript expression is simply the coming together of two or more values to become one using an operator.
  • Whenever we carry out mathematical operations on two or more numbers using operators(+, -, /, *, %) to get another number, we have carried out an expression.
    var three = 2 + 1; //var three = 2 + 1 is an expression brought together with operators (=,+)
  • Whenever we bring two variables together with the hope that they will become one, that is an expression.
  • Whenever we bring two strings together to form another longer string, we are carrying out an expression.
  • Whenever we combine two or more statements with operators to test their true or false state. We are forming an expression.
    var bool = 5 < 6; //var bool = 5 < 6 is an expression brought together with operators (=,<)
  • Whenever we assign a value to a variable so that they become one, that is an expression.
A statement may or may not be an expression.
var i; //Not expression
var z = 3; //Expression
A variable may or may not store an expression.
var i = 1; //Not storing an expression
var z = 3 + 4; //Storing an expression
An expression may or may not be stored on a variable.
var d = 2 + 4; //Stored on a variable
alert(8+7); //8+7 - an expression not stored
CONCATENATION CONCATENATION is the joining together of two or more strings. It is an expression that involves one or more strings to produce another string. Strings can also be concatenated with other data types (e.g numbers, booleans) to get another string.
var x;
x = "The number is " + 5; //A string and a number to form another string
Basically, concatenation in JavaScript is done using the addition operator(+) but you may also use the string's object method, concat(), which can be called on a string whether it was created explicitly or implicitly. EXAMPLE Using addition operator(+)
<script>
var myFirst = "Hello";

var mySec = "World";

alert(myFirst+mySec);
</script>

Copy PRACTICE IT

Using concat() method
<script>
var myFirst = "Hello";

var mySec = "World";

alert(myFirst.concat(mySec));
</script>

Copy PRACTICE IT

ADD SPACING
<script>
var myFirst = "Hello";

var mySec = "World";

var myStrs = myFirst+" "+mySec;
alert(myStrs);
alert(myFirst+" James");
</script>

Copy PRACTICE IT

<script>
var myFirst = "Hello";

var mySec = "World";

alert(myFirst+" ".concat(mySec));
alert(myFirst.concat(" "+mySec));
</script>

Copy PRACTICE IT

It is very important you understand strings' concatenation as you will be concatenating strings a whole lot of the time for output.
<script>
var pr = 500;
var rate = 10;
var years = 2;
var interest = (rate/100) * pr * years;

//CONCATING OUTPUT
alert("Investing a principal of "+pr+" for "+years+" years at the rate of "+rate+"% will yield an interest of "+interest);
</script>

Copy PRACTICE IT

SUMMARY
  1. A JavaScript expression is two or more values/variables/values and variables joined together using an operator to become one.
  2. Concatenation is an expression that involves a string in order to produce another string.
  3. Strings and other data types can basically be concatenated using addition operator (+).
  4. We can also use the string object's method, concat().
Take a short quiz on JS Expressions & Concatenation.
Ask a question or tell us if JS Expressions & Concatenation is easy or not.
cent?

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.





StackBeginner 2021 © Joseph Omamode