Basic Syntax And Rules In JavaScript

Welcome back, guys! I hope you are well and having a great day. In today's tutorial, I will discuss the new topic "Basic Syntax and Rules in JavaScript". Learning grammar for a spoken language is necessary before you start writing it. There are rules and regulations you have to follow to write. Similarly, all programming languages have their grammar/syntax and rules which you have to follow in order to execute.

JavaScript Is Case Sensitive

  • JavaScript is case sensitive programing language. Therefore variables, function names, language keywords and any other identifiers must have written with a consistent capitalization of letters.     
Let me show you an example. 
  • In this statement "alert" is case sensitive and if I change the first letter of "alert"  "A".
Alert(“I am learning JavaScript”);
This code sample has uppercase "A" and instead of printing the expected "I am learning JavaScript". The error will appear (alert is not defined) and code would not run. So it is important to be careful with syntax.  Here are some rules you should keep in mind. 
  • JavaScript keywords such as if, for and alert are always lowercase.
  • Built-in objects such as math and date are uppercase or capitalized.
  • DOM(Document Object Model)  are usually lowercase but the methods are often a combination of lowercase and uppercase.
Variable, Function & Objects Name
  • You can define or name your own variable, function and objects.
  • There is no limit in choosing their name you can use uppercase, lowercase and underscore(_) or Numbers.
  • The name must begin with letters or underscore and it can't start with a number i.e getAgeBy_Name,  getHeightUnder_2
  • There is no limit for you in choosing a variable name with uppercase or lowercase, as I told before JavaScript is case sensitive: age, Age, AGE will be considered as three different variables.
  • So make sure to use the same variable when calling it or referring.
  • Most of the code in JavaScript is a statement. Like, this is a statement of JavaScript.

alert(“I am learning JavaScript on https://www.theengineeringprojects.com/”); 

  • Statement can be used to change the color of webpage, background or position of picture etc
  • Always put a semicolon at the end of the statement because each statement in JavaScript ends with a semicolon.
  • White space is not sensitive. You can add spaces and line-breaks as much as you want.

Syntax of JavaScript Comment

The syntax of comment is similar to CSS. JavaScripts comments are used to explain or understand the code, and to make it more readable. Suggestions or warnings can help the end-user too.  With the help of comment, you can stop code from execution while running or testing alternative code. There are two types of comment in JavaScript.
  1. Single Line Comment
  2. Multi-Line Comments
Single Line Comment
Single line comment represents double slash forward (//). You can use it before and after the code.  When you add these two forward slashes (//), all of the code/text to right of them will be ignored. You can see an example in the below picture.
Multi-Line Comment
The multi-line comment is more convenient than single-line comment, you can use it as a single line comment and multi-line too. Multi-line comment represents forward slash with stearic /* and end with a stearic forward slash */.
/* Your comment here */
You can out a segment of code by adding multi-line comment in it. You can look in the image for more detail. These are so helpful in coding.  You can add any comment at any time as you want for your preference. Look in the below image for a more clear example. It is really important for a JavaScript developer to know how JavaScript program executes internally. The code in JavaScript executes from top to bottom. If you want some particular statement to perform in order then you have to write it with a specific order.
Data Types in JavaScript
There are three data types in JavaScript.
  • Number: Number represents all the integer, decimal  and float type etc. i.e 4, 4.345
  • Boolean: Boolean is going to store if the statement is true or false. True/false
  • String: String should be either in a single quote or double-quotes. "I am learning Js" 'Mystring'

Google Chrome Development Tool

  • Google developer tool is available in the google chrome browser. Since you all know the google chrome browser already. So move forward.
  • Hence, all you have to do is press f12 in your google chrome browser.  It will bring a tab like this as you can see on the right side of the Image.
It will take you to the element bar, you can go to the console bar by clicking on it.
  • Element tab shows the HTML of the page.
  • You can open the Javascript file further by right-clicking on it and go down the “open link in resources panel”
  • In the resources panel, you can see the javascript file.
In console Panel, you can type live Javascript in the browser and test it. I will show you with example.
  • Open a new tab in your browser and press f12.
  • Now go in console tab and type this code:
    alert("I am doing this alert form in console");
    And press enter. Then the dialogue box will appear instantly. Don’t worry about this “undefined message”.
  • You can type different numbers in here and get your result, addition, multiplication, subtraction and more. See in the image.
  • Now go back in element tab and you can see the console panel in the last. Look in image:
  I hope you have understood the basic syntax and structure of JavaScript. In the next tutorial, I am going to share more detail of JavaScript. If you have any question related to this topic, comment below. I will answer you immediately.  Thank you so much for reading it and keep reading more article and grow your knowledge in coding. If you want to learn any other language comment below. We will make sure to share those languages with you too.

Analog Vibration Sensor Library for Proteus

Hi Guys! Glad to see you here. I welcome you on board. In this post today, I’ll be discussing Analog Vibration Sensor Library for Proteus. I have already shared the digital Vibration Sensor Library for Proteus, you should check that as well. I’ve been adding brand new libraries for proteus covering sensors and Arduino boards. I’ve recently discussed Analog PIR Sensor Library for Proteus and Analog Flex Sensor Library for Proteus. You may be stuck into thinking I’ve previously shared those libraries but they were libraries covering digital PIR and digital Flex sensors, here we discussed analog libraries for both PIR and Flex sensors. Before I pen down how to download and simulate Analog Vibration Sensor Library for Proteus, let’s discuss what is vibration sensor first. A vibration sensor is mainly used to monitor the vibration of industrial machines. It is also called a piezoelectric that plays a crucial role in the proper working of industrial machinery. If vibration values increase from the industry standards, they can severely affect the overall working of the machine and in the worst case can put the machine at a grinding halt. To avoid this, we use vibration sensors that give the warning signal if vibration exceeds the desired values. These sensors are attached to the alarm system that produces audible sound indicating the machine is in danger, thus results in the deactivation of the entire machine. Vibration sensors are based on the piezoelectric effect to observe the small changes in pressure, acceleration, force, and temperature. These changes are converted into an electrical signal. Air fragrance can also be monitored by vibration sensors. They monitor the air fragrance and detect its capacitance and quality. I hope you’ve got a clear idea about the vibration sensor now we’ll download and run the Analog Vibration Library for Proteus. I’ve added both a simple simulation of the vibration sensor and a simulation with the Arduino Board. Let’s get started.

Analog Vibration Sensor Library for Proteus

  • Click the link given below to download the Analog Vibration Sensor Library for Proteus.
  • As you download this file, it returns further two files named Proteus Library and Proteus Simulations.
Analog Vibration Sensor Library for Proteus Click the Proteus Library folder that contains four files as follow:
  • VibrationSensorAnalogTEP.HEX
  • VibrationSensorTEP.HEX
  • VibrationSensorTEP.IDX
  • VibrationSensorTEP
Now copy all files given above and place them into the library folder of your Proteus software.  
  • In case you don’t have proteus software in your system, you can read this post covering how to download and install proteus software.
  • After adding the above files, start the proteus software and if it’s already running, close the software and restart again.
  • Now click the ‘P’ button to search for the ‘analog vibration sensor’ libraries that you’ve recently placed.
  • As you search it, it will return the figure as given below:
  • Select the sensor and click OK. Now you’ll see your cursor has now started blinking with the sensor that shows you can place your analog vibration sensor anywhere in the workspace available on the proteus software.
  • As you place your sensor, it will show the figure below:
Now we'll look into the analog vibration sensor pinout.

Vibration Sensor Pinout

The vibration analog sensor contains 4 pins as follows.
  • OUT = First is an OUT pin that is connected with a voltmeter that represents the output voltage against the variable resistor attached to the TestPin.
  • GND = Second is a ground pin that is attached to ground voltage.
  • Vcc = Third is the voltage supply pin that gets 5V to power the vibration sensor.
  • TestPin = Forth is the TestPin. This pin is only available in the proteus simulation. You don’t find it on the analog vibration sensor in real. When this pin is LOW, it shows no vibration and when this pin is HIGH it represents the vibration on the machine.

Adding HEX File

Now we’ll add the HEX file to run our vibration sensor simulation. Right-click the sensor and reach the ‘edit properties’ option and double-click the sensor it will pop up the same edit properties panel. Browse the Sensor’s HEX file option and look for the HEX file. You can find the HEX file in the library folder. Same HEX file that we have recently placed in the library folder. Select this HEX file and click OK. Now we’ll attach a simple circuit with the vibration sensor to run our simulation.

LC Circuit

  • We need to design a simple circuit to run this sensor in the proteus workspace. We’ve designed and attached the LC circuit with the OUT pin of the vibration sensor.
  • And TestPin is connected with a variable resistor. Both variable resistance and voltage we get on the voltmeter attached with the OUT pin are inversely proportional to each other.
  • When variable resistance is set to the maximum value the voltage on the voltmeter will be zero and when variable resistance is set to the minimum value (zero) it shows the maximum voltage i.e. 4.98V on the voltmeter.
When you run the simulation it will return the result below:
  • You can see the voltage appearing on the left vibration sensor placed on the proteus workspace is 2.56V because TestPin attached with the variable resistor is set to almost half of the resistance value.
  • I told you earlier I’ll show you both simple simulation and the vibration sensor simulation with the Arduino Board. If you are interested in the Arduino Library for Proteus, check this post where I have added six Arduino Boards Libraries for Proteus.
Now connect the voltage on the OUT pin with the analog pin i.e. A0 of the Arduino Board: When variable resistance is maximum the voltage on the voltmeter will be zero and its equivalent analog value across LCD attached with the Arduino Board will be 0019 and when the resistance on the variable resistor is minimum the voltage will be 4.98V and its equivalent analog value on the LCD will be 1019. This is it. I hope, you’ve got a clear insight into how to download Analog Vibration Sensor Library for Proteus. If you have any questions, you can ask me in the comment section below. I’d love to help you with the best of my expertise. Feel free to pop your suggestions about the libraries you think should be included in the proteus library database, I’ll design and add them to the database. Thank you for reading this article.
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir