Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 9, 2022 09:16 pm GMT

Javascript 1O1 series : Learn syntax, variables and datatypes

image from https://www.programminghunk.com/2020/02/variables-in-javascript.html<br>

Youll learn :

Javascript syntax, statements, how to define variables and how to use it, and also well 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
Execution order

comments :

everything in your javascript file will be executed, comments wont.
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

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 (variables name usually is string) and then we can give it a value or not.
for simplicity well stick with var, later in tutorial well learn about another ways.
you can change variable value whenever, to whatever you want by using the assignment = .
e.g.
Image description

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 dont need to define its values type explicitly, we just say
var x = 5;
const y = [];
and the browser will understand the datatype by it self.
Image description
dynamic javascript types

also javascript types are dynamic, it means you can change the type that variable hold to whatever type you want, lets 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 its index (its numeric position in the array). well 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
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
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
Numbers in js

Boolean :
const boolean = true
boolean can only have two values : true or false
Image description
boolean values.

and much more of data types that available in this great language well 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, github and my portfolio.


Original Link: https://dev.to/osam1010/javascript-1o1-series-learn-syntax-variables-and-datatypes-3cic

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