Basics of JavaScript

Basics of JavaScript

Functions

A function instructs a machine to perform a specific action. Functions can accept arguments to supply the computer with more data.

EXAMPLE

drawBox(blue);

Arguments

An argument is additional data that instructs a function on how to operate. A function call encloses arguments in parentheses.

EXAMPLE

drawBox(red);
print('hello');

Strings

The term strings refers to letters, words, and sentences. To begin and end strings, use quotation marks.

EXAMPLE

drawBoxes('royg');

Variables

In one of my posts, I talked about variables. You can use a variable to make several references to the same piece of data.

EXAMPLE

var myExample = 'a variable';
print(myExample);

Arrays

A list of things makes up an array. Arrays can hold various forms of data (numbers, strings, and even arrays). Array nesting is the act of putting one array inside another. The symbol for it is [].

EXAMPLE

var array = ['blue', 'orange', 5, 10, [50, 10]];

Array indexing starts at 0.

If statements

When a test returns true, a if statement enables you to execute a particular block of code.

EXAMPLE

var number = 5;
if (number === 5) {
drawBox(blue);
}

If...else statements

An if...else expression performs a test. If block =true, then block= false.

EXAMPLE

var number = pickRandom(10)
if (number ===7) {
 print ('It is 7!');
} else {
 print ('It is not 7!');
}

Objects

An object stores multiple values that have property names. This makes it easy to access later in the code.

EXAMPLE

let info = {
 name : Sam
 age : 15
 class : 8
};

Summary

Here are the topics you may want to learn as a beginner:

  • Functions
  • Arguments
  • Strings
  • Variables
  • Arrays
  • If statements
  • If...else statements
  • Objects

There are more topics in JavaScript, but as a beginner, these are the major topics that you can learn.