Introduction
In this blog article, we are going to touch on basics of programming. This will be featured in Modern JavaScript Primer. You may preorder the book at Modern JavaScript Primer for beginners . An early preview of the book will be released on 7/01/2022.
Let's jump into the basics. In the book, we shall cover the following topics as part of the basics:
- Introduction to Data types and basic data structures
- controls structures
- Loops
- Functions
- Program construction basics
Variables and constants
Variables are values referred to by a label that may change within the program execution. Introducing a variable in your program is known as variable declaration. Creating a variable and assigning an initial value is known as variable declaration and initialization.
let output // declaration, this will will hold value 'undefined'
let input = 0.16 // declare and initialize with 0.16
Variables change within the program execution and may be reassigned to new values as the program exectes.
Note:
Programs are executed sequentially, line by line (except for mutlithreading) from the first line to the last line or when the program finds a return
keyword. Termination of the function/program terminates and return
s a value to the calling function which may return or continue exectuting.
Constants
Constants are like variables with exception that once declared, they can never be reassigned to hold new values. They represent entities that will never change during the program execution.
Note:
It's good practice to use constants with meaningful names than magic constants as they become hard to read as program grows in complexity.
It's common to give constant name in upperase seperated by an _ underscore, to show that they are constants.
const VAT_RATE = 0.16
const POINT_OF_VIEW = 45 // camera point of view
const ASPECT_RATIO = 2.0 // aspect ratio
These examples use modern JavaScript for demo. In other languages (statically typed languages), one has to provide a type for the variable. For instance in C++:
String catName = "Nancy";
Summary
Programming majorly involves manipulating data, storing the data, sending the data over the HTTP or displaying them nicely to a user assuming web/Frontend or mobile development.
- Use meaningful and descriptive names.
- use named constants instead of magic constants.
Merry Christmas 🎄🎄🎄
Top comments (4)
This post was originally published at naftalimurgor.netflify.com
Thanks for preordering the book! Thanks everyone
Can't say more. Thanks everyone
Thanks for the insight. I never knew the listing feature existed.
Some comments have been hidden by the post's author - find out more