Skip to main content

Learning Javascript Part II

Learning Javascript Part II


Writing computer programs is all about controlling information. Information is called data in programming that we store in our PC programs. For instance, your pet's name is a bit of information, as is its breed and it will be called data.

In JavaScript, there are three basic types of data: numbers, strings, and Booleans. Numbers are used for representing integer values like this:

5;


Strings are used to represent any kind of text. For example your pet'sname can be represented like this:

 "My pet's name is kitty";

I know i am bad at giving examples but hope it gave you a idea about strings.

Next is Booleans. Booleans are values that can be true or false like you can assign the value true to sentence "My pet's name is kitty".

There are distinctive approaches to work with every data type. For instance, you can multiple numbers with each other, however you can't do it with two strings  having two numbers.

For Example:







Similarly with Booleans, you can verify whether two values are both true.

By the Way if you have seen Part 1, visit it before continuing further.

Variables

In javascript you can give names to values so that you can use these values later on.


 

You can think about a variable as a container that you can fit one thing in. In the event that you put something else in it, the primary thing leaves. For instance, here's the manner by which you'd make another variable called catname





 



Write this in the browser's console window.Hit enter and you will get a message in next line as undefined,which simply means that the catname doesn't have any value. This above step is known as declaration.A variable is an address in memory so we just now named a memory space but this is currently empty.To give value to this we write in console the above line without semicolon as the semicolon means the line ends here and put equal sign in front of it then write the value you want to give.I want to store the the name "kitty" in this variable.









The variable catname now stores the value kitty. When you first give value to a variable it is known as initialization.

Did you noticed that we gave a string value to this variable but you may give a number or boolean value to it like shown below.You can change the value from a number to string or to boolean Javascript won't mind it but will simply overwrite it.






 

Some Rules:

The variable name catname is known as identifiers.These can be long or short.lets look at the rules for writing these :

They may contain letters, digits, underscores, and dollar signs.

It must start with a letter

Remember these names are case sensitive

Some reserved words such as JavaScript keywords can't be utilized as names.


Operators


Lets learn how to change the variable's value after its initialized. To do this we can simply give it a new value as we earlier did or we can perform some operations on them.















To perform operations on variables javascript offers some operators. For those who is thinking what an operator is "An operator is a symbol that makes the script perform a specific mathematical or logical manipulation.".So lets learn about them,

Arithmetic Operators

It is used to perform mathematical calculation

x = 2 + 4;  // 6 addition
x = 7 - 2;   // 5 subtraction
x = 3 * 5;  // 15 multiplication
x = 100 / 10;   // 10division
x = 7 % 5; // 2 - modulus (division remainder)

 

Assignment Operators


It is used to assign a value to a vaiable.
x = 0;

Increment and Decrement Operator


In JavaScript increasing by 1 is called incrementing, and decreasing by 1 is
called decrementing. The quick way to do this is ;
catAge++; // catAge = catAge+1;
catAge--; // catAge = catAge-1;

 

Comparison Operators


 These return true or false based upon comparison of two values

num = (2 == 3); // False - equal to
num = (2 === 3); // False - identical
num = (2 !== 3); // True - not identical
num = (2 != 3); // True - not equal to
num = (2 > 3); // False - greater than
num = (2 < 3); // True - less than
num = (2 >= 3); // False - greater than or equal to
num = (2 <= 3); // True - less than or equal to

There are some other operators but we are not going to discuss about them here

So this is it for this post, next time we are going to learn about Arrays in javascript so please subscribe to Deecoder and share this post if you like this.
 
 






Comments

  1. Great post! I don't even know what javascript but it was pretty cool to see what you've learned!

    ReplyDelete

Post a Comment

Popular posts from this blog

Gdevelop: How to manually export to android or ios using Cordova

In this post we will see how to export your Gdevelop project to android or ios manually using cordova. Gdevelop provides a web service for export to android or ios. But it is a paid service it only provides 2 exports/day. By paying for subscription you support developement of Gdevelop but it you don't want to pay, Gdevelop provides you with an offline option. We will see how we can export Gdevelop project as a Cordova project and build it using a cordova by ourselves locally on our computer. Obviously for FREE!!. Lets get started. Prerequisite  I am assuming you have Android SDK installed on computer.If not then download it and install it first. I am not covering it here as it is a general thing and you can find plenty of tutorials and also that it will make this post unnecessarily longer. Also cordova requires node.js installed on your computer..Installing is as easy as downloading the installer and running. Link :  https://nodejs.org/en/ After installing the node.js

Gdevelop 5 : How to Find Distance Between Two Objects

In this Post we will learn how to find distance between two objects in Gdevelop 5. Many times we are required to find distance between two objects Gdevelop provides inbuilt functionality for this purpose just let's get started. Creating A Project We will start by  creating an empty  project.  So click on create a new project and name it distance between two objects.  Let's quickly add a scene and a sprite. Let's add another sprite. I will also add text to display the distance between these two sprites.  Let's add these objects to the scene.Now let's head over to the event sheet and Add an event.The condition will be empty and action will to display the distance. So choose the distance choose->modify text and operator be set to equal and click on then expression button. We first have to convert expression to string choose conversion and then number to text. Click on the expression button and then search square root. Click on expression button again and this time

Gdevelop Game Debugger and Profiler Tutorial

Gdevelop Game Debugger and Profiler In this post we will learn how to use Debugger. It helps us remove bugs from our game. A bug is basically a error or fault in our game that makes game work in in intended. A debugger helps remove bugs from our game. Debugger    Its a tool that is used to inspect the variables and objects of game at runtime. It gives us information about the objects and variables in the game. By using this information we can track the bugs in our game. It Debugger as it helps us remove the bugs from our game.  Using Debugger we can inspect  global variables, scene variables and variables of instances of  objects in the game. We can then analyse this information to find problems in our logic and game. How to Launch game with the debugger To use the debugger, we need to launch the game preview using the Debugger. To do this just go to the toolbar of a scene editor, click on the “Debug” icon and then choose “Preview with debugger and performance

[Inkscape] : How to import inkscape SVGs in Html file

[Inkscape To Web]: Make beautiful sites with SVGs In this tutorial we will make a SVG drawing in Inkscape and will use it in a webpage. The goal of this tutorial is to know how to make beautiful SVG Drawing for your website. Before starting you should have following things, Familiarity with SVGs/Inkscape and HTML  Inkscape Installed. How to Embbed Step 1: Open Inkscape. Now make a simple Shape. I am making a polygon,                                       [Click on the Image to Enlarge] Step 2: Now save it as a svg. The inkscape saves its files as svgs but it is not compatiable with html. It a lot Inkscape specific(useless) data. To save it as plain Svg. Click on File->Save as. Then from dropdown box in the dialog box. Choose the .PlainSvg.  [Click on the Image to Enlarge] Step 3: Now open your favorite code editor i am using the brackets. Now open this .svg File that we just saved using Inkscape.   [Click on the Image to Enlarge]

Blender 3D Graph Builder Addon Tutorial

Graph Builder Addon lets you generate 3D Bar Graphs from simple values. The bars can have simple animation.In this tutorial,I will be making a simple 3D graph in blender with this Addon. You can download the addon on Github and download the data that I am going to use  and end result from here , in case you want to follow along . Though you can use any data you want, just make sure data values are integer and each value is separated by a comma.  Just to give you an idea Graph Builder addon work like this.   Installation Just extract the file. Open Blender and go to user preferences and select “install from the file”. Then locate and choose the graph.py file. Tutorial: There are 4 panels in the addon. We will go to them one by one and see what are their usage. Step1:  Copy Data into the data values and set the factor. Here, you want to enter the values that will be used to draw the graph. Each value represents a bar on the graph. Values must be s

How to make Make money with Inkscape

How to make Make money with Inkscape Inkscape is a free and open source but professional vector graphics editing program for Windows, Linux and Macintosh. A Free alternative to Adobe Illustrator and is used by a lot of enthusiasts, art students and artist all around the world. Ah.. you knew this already? Right!! Otherwise why would you read this post. So here are the ways to make money with inkscape. Selling Vectors This is an obvious one but not as easy as it seems, you see there is a lot of competition, you will  hundreds of sites if not thousands for selling vectors with tens of thousands of sellers on them also it's not that you can sell anything made with inkscape you need to follow some standards.For example here is an article which might be helpful, http://sellingvector.blogspot.com/p/how-to-start-selling-vectors.html?m=1 Tutorials If you want to know more about how to sell vectors created in inkscape then you should read

A Quick Look at Machine learning

A Quick Look at Machine learning Ever heard of ‘Artificial intelligence’, of course you did after all we all watch sci-fi movies. But if you ever tried to know more about AI then you might have heard about Machine learning. Also in past few years it's been a hot topic in computer science. So, what is machine learning??. Let's talk about this…, Computer are everywhere today, even in your pocket (your phone).They help us do a lot of thing but in reality these are just calculators with logic and control circuitry.Therefore we can program them to do different tasks.But there are scenarios where we cannot predict the situation and its nearly impossible to program the computer for that.For instance , CCTV Cameras are installed at many places and surveillance has become very easy as it can be done remotely but we need a human to process the video from the cameras as a computer cannot tell us if everything is ok or not.Now imagine if the computer can automatically dete