Variables and Data Types
Variables are used to store data in a program. Variable has a name and a value. There are two parts of creating a variable; declaration and initialization. Once it’s created, you can set its value.
The number type represents both integer and floating-point numbers. You can perform *, /, +, - etc operations on numbers. Besides regular numbers, there are special numeric values like Infinity, -Infinity, and NaN (Not a number).
A boolean has only two values: true or false. It is commonly used to store yes/no value.
A special value that represents “nothing”, “empty” or “unknown value”.
A special value which means ‘value is not assigned’.
All other types are called “primitive” because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities.
An array is a single object that contains multiple values enclosed in square brackets and separated by commas.
Math and Logic
A really important part of programming is doing math and being able to compare values in order to make decisions in code. The outcome can be either true or false (boolean type).
Loops allow you to run a piece of code a certain number of times or until a certain condition is met. They’re incredibly useful. They can be used to carry out actions on every item in an array or printing all the data inside an array or in searching etc.
- A for loop contains three statements, separated by a semicolon (initialization, condition, updating or final expression). The loop first runs the initialization and then checks if the condition is true. If it is true, it runs the block of code inside and finally runs the updation code. After updating, it again checks the condition and performs these steps again and again until the condition becomes false.
- A while loop repeats a block of code until a condition is met. For any update, you can do it inside the while loop.
Functions are blocks of code that you can reuse and call anytime you want to execute it. A function can take values, called arguments, and can return a value.
If you want to learn these concepts and much more from experts, consider enrolling in our Full Stack Development Learning Path. We teach frontend, backend, databases, dev tools and deployment tools from basics to advanced.