In this article, we’ll cover:
- Variables and Data Types
- Math and Logic
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.
- Number: 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).
- Boolean: A boolean has only two values: true or false. It is commonly used to store yes/no value.
- Null: A special value which represents “nothing”, “empty” or “unknown value”.
- Undefined: A special value which means ‘value is not assigned’.
- Objects: 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.
- Arrays: 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 for 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 semicolon (initialization, condition, updation 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 for 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 updation, 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.