Javascript 1O1 series : Learn syntax, variables and datatypes
Tags: javascript, webdev, programming, tutorial
Published: 2022-04-09 21:16:58

![image from https://www.programminghunk.com/2020/02/variables-in-javascript.html
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hs6nhxd7e9pcqp035j8o.png)

## You’ll learn :
Javascript syntax, statements, how to define variables and how to use it, and also we’ll go through the most important datatypes in this language
Syntax and statements :
Computer programs are set of instruction will be executed by computers to get results, these instructions are called statement in programming, and syntax is set of rules to define how the code is constructed . so we can say A JavaScript program is a list of programming statements.
JavaScript statements are composed of:
Values (either variables or constants), Operators, Expressions, Keywords, and Comments.
and these statement are executed in the same order as they are written
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0z6vy4l3qx0fxv08eyf.png)
Execution order

## comments :
everything in your javascript file will be executed, comments won’t.
when you are coding and you had an idea, you can simply write it on the same javascript file as comment and the browser will ignore it.
there are two types of comments, single line and multiple lines comments.
// this one line comments and will be ignored when executing your code
/*
this is multiple line comments,
and will be ignored when the browser executing your code
*/
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x2tlxab3m97kwpnlnca6.png)
 
comments in javascript

## variables :
variables are containers to store or to contain some values, you can use these values by their given name (identifier) .
to initiate a variable in javascript, you use var or let keywords, then we give it a name (variable’s name usually is string) and then we can give it a value or not.
for simplicity we’ll stick with var, later in tutorial we’ll learn about another ways.
you can change variable value whenever, to whatever you want by using the assignment = .
e.g.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oub5rn5qqhimg08p20cb.png)
 
variables in js

## data types :
as we said before, variables are containers that contain certain values, but what it could be these values ?
datatypes are the valid types of values that the variable can have,
such as numbers, strings, boolean, character, arrays, objects just to mention a few.
javascript is dynamic language, what does it means ?
it means when we define a variable, we don’t need to define its value’s type explicitly, we just say
var x = 5;
const y = [];
and the browser will understand the datatype by it self.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jse7t1rypk20vopj98ag.png)
dynamic javascript types

also javascript types are dynamic, it means you can change the type that variable hold to whatever type you want, let’s see how
tl;dr : a variable of the same name can be used to hold different data types

## Some of javascript data types :
**Arrays :**
`var array = [1, 2, 3];`
an array is an ordered collection of values, each value called an element, you can access any element by it’s index (it’s numeric position in the array). we’ll talk about arrays in-details later.

**Objects :**
var object = {};
object is a variable contains set of properties, each property has a name and value.
or 

> An object is a composite value: it aggregates multiple values (primitive
> values or other objects) and allows you to store and retrieve those
> values by name. from “javascript the definitive guide “


JavaScript objects are written with curly braces {}.
Object properties are written as name:value pairs, separated by commas.
you can access any object property using objectName followed by dot operator ( . ) and the property name
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3jkvs0hi3mkvvr5rxk9.png)
objects in js

**Strings :**
var string = “string”
strings are series of characters like “this is a string”, simply bunch of characters are written with quote, You can use single or double quotes.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofe81r3wk4jd223y00bi.png) 
strings in js

**Numbers :**
const number = 5
JavaScript has only one type of numbers , it hold all type of numbers with, or without decimals
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eko95grkc02c2r8my1va.png) 
Numbers in js

Boolean :
const boolean = true
boolean can only have two values : true or false
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42l6spf34h5wuimy6615.png)
boolean values.

and much more of data types that available in this great language we’ll see it in later lesson on this tutorial.

Thanks for reading, and feel free to ask any question about javascript or about this series and i appreciate any feedback to improve My content.
find me on [twitter](https://twitter.com/Osam1010), [github](https://github.com/osama865/) and [my portfolio](http://o-portfolio.netlify.com/).