Daphnie's Code Life

Web Developer Journal With my portfolio done, for now, I moved on to basic JavaScript this week. I have a little experience with JavaScript. I took a course last year but did not absorb much. I checked out when jQuery was introduced. With FreeCodeCamp, jQuery comes before JavaScript. It did not make sense, but it worked for me this time. This is what I worked on this week:

Commenting code

Comments are notes for myself or others that are reading my code.

// This is how to comment.
/* This is how to comment
many lines */

Declare JavaScript Variables

Declare a variable by using var in front.
var myName;

Storing Values

Store a value in a variable with the assignment operator.

myVariable = 6;

Initializing Variables

Initialize a variable to an initial value in line it is declared

var myVar = 7;
This is a new variable called myVar with an initial value of 7

Uninitialized Variables

Math operations with no defined variable is Nan or “Not a Number”

Case Sensitivity in Variables

JavaScript variable names are written in camelCase

var sum = 1 + 2;

Subtraction with JavaScript

var difference = 27 – 13;

Multiplication with JavaScript

var product = 5*2;

Division with JavaScript

var quotient = 45/0;

Increment with JavaScript

Increment or add 1 to a variable with ” ++”
b++;
this means b + 1;

Decrement with JavaScript

Decrement or decrease a variable by 1 with “–”
b–;
this means b – 1;

Multiply Decimals with JavaScript

var product = 3.0 * 0.0

Divide Decimals with JavaScript

var quotient = 0.0/ 3.0;

Find a remainder in JavaScript

% is the remainder operator
5 % 2 =1
Math.floor(5/2)=2 (Quotient)
2 * 2 =4
5 – 4 = 1 (Remainder)

Compound Assignment with Augmented Subtraction

-= subtracts a number from a variable
myVar -=4;

Compound Assignment with Augmented Multiplication

*= multiplies a variable by a number
myVar *= 3;

This week was basic math with JavaScript. Nothing hard so far. I have not used any of these functions because I have not written much JavaScript. I am interested in how I will use these functions going forward with various projects.

This week will be busy. On top of daily JavaScript lessons, I will do work for a Chingu Cohort and add a few HTML and CSS lessons. I wanted to join the cohort to team up with other newbies and add good projects to my portfolio. I hope everything goes well.

## One thought on “Basic JavaScript”

1. anygivensolutions says:

Very nice and informative post. It can definitely serve as a quick reference guide for me. Thanks for sharing!!