DEV Community

Ahumuza Ceasar
Ahumuza Ceasar

Posted on

Beginning JavaScript: Part 2

JavaScript Variables

A variable in JavaScript is a named storage for data. With variables we can store data such as numbers in the variable. Think of a chat application , Each user on the app has a username and maybe an age. Such information can be stored in a variable then be reused once needed. To declare variables in in JavaScript, we use the let and var keywords.

Example:

Image description

On line 1, we declared a variable called userName and on line we assigned the name “Ceasar” to the variable . To print the name to the console we invoked the console.log() function on line 3.
We could also assign values directly to variables as seen on line 6. Both ways would return a working program. But I love assigning values directly and write less code.

Output:

Image description
Data Types

Data types in JavaScript define the different data kinds or type that you will be working with to store and handle data. It’s important to learn about data types as you will be able to handle information very well. Among these include numbers,strings,booleans and null.

a) Numbers
Among these include positive and negative integers. With these include numbers delimeted with a decimal point also known as floating point numbers

Image description

b) Strings
Strings are used to represent and work with a set of characters. They are created by surrounding them in single or double quotes. For example, your name is a string.

Image description

c)Booleans
This is a data type that can either evaluate to true or false. Let’s say we would like to check if a user is logged in to our chat application, We could use booleans.

Image description

Latest comments (0)