Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 29, 2021 04:53 pm GMT

JavaScript Made Easy: Part 4

For this post, we will go over various topics such as comments, assignment operators, and arithmetic operators. As always, open up a repl and code along with this post. You learn more by doing it yourself, and you will build muscle memory. Log all of these operations to the console in your repl and use comments to reinforce what you are doing.

Comments

Comments are fairly easy to understand. There are two types of comments in JavaScript. The first is a single-line comment. The second is a multi-line comment. Here are some examples:

// This is a single-line comment./* This is a multi-line comment.Everything inside of this commentwill not be run. You can also use comments for not only notes, but you can comment out a block ofcode that you want to leave out butnot delete*/

Assignment Operators

There are several different types of operators in JavaScript:
Assignment operators assign a value to a variable. You learned about this in previous lessons.

const currentLesson = 4; //assignment operator

Arithmetic Operators

  • Addition

The addition operator is used for adding numbers, adding booleans, adding variables, and for combining strings together.

2 + 2;// expected result: 42 + true;// expected result: 3'I am a ' + 'Developer';/* expected result: "I am a Developer"Notice that there had to be a space added at the end of the first string*/2001 + ' is my graduation year';// expected result: "2001 is my graduation year"
  • Multiplication

The multiplication operator multiplies numbers or numbers stored in variables. Here is an example:

//multiplying numbers5 * 3; //equals 15 //multiplying variablesconst number1 = 5;const number2 = 3; const number3 = number1 * number2; // equals 15
  • Other operators that can be used to do arithmetic the same way are:
5 - 5; //subtraction3 ** 4; /*       exponentiation       expected output is 81       same as 3 to the 4th power       */1 / 2; //division12 % 5; /*modulus       returns the remainder        after division       */++; // increment (increases a number by 1)--; // decrement (decreases a number by 1)

I hope you have enjoyed this post! Please check out the entire "JavaScript Made Easy" series by David Tetreau. There will be a new post daily.


Original Link: https://dev.to/dtetreau/javascript-made-easy-part-4-4da9

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To