Javasript Tutorial Articles


How to Check if a Variable is Undefined in Javascript

To check if a variable is undefined in Javascript you can use the typeof operator or just the variable itself. For an undefined variable, the variable will return undefined. The typeof operator will also return a value of undefined. An undefined variable in Javascript is a variable that has been... Read more

How to Check if Variable is String in Javascript

You use the typeof operator in Javascript to check if a variable is a string. The typeof operator returns a value of string when the variable is a string. Simple String Check Example in Javascript var computerbrands = ["Apple","HP","Dell","Lenovo","Acer","Asus"]; var slogantext = "Road rage burns the tires."; typeof(computercompanies); // object... Read more

How to Use Javascript Variable in HTML

You can only use Javascript variable in HTML by linking the Javascript variable to a HTML element using an id or class attribute. Linking Javascript Variable to HTML Element Create an element in HTML. Code <p>Content is loading ...</p> Assign an id to the element. Code <p id="content-holder">Content is loading... Read more

How to Check if Checkbox is Checked in Javascript

You can check if checkbox is checked or not in Javascript by using the checked property of the checkbox. Start by creating a checkbox element in HTML. <label for="legal-terms"> <input type="checkbox" id="legal-terms" /> I agree with the terms and conditions </label> In Javascript you can check the state of the... Read more

Can Static Website Have Javascript?[Answered]

Static websites can contain Javascript. Infact, most static website have Javascript. Javascript is added to static websites through Javascript file or inline through a script tag. A website is considered a static website if the server delivers the files stored in the server as without any change or manipulation. Dynamic... Read more

Where to Put Javascript Script in HTML

You can add Javascript script in the <head>…</head> section or in the <body>…</body> section of your HTML website. Add the script in the head section if you want it to be loaded first. Otherwise, put the script tag as the last item just before the closing body tag(</body>). Script in... Read more

How to get and set margin in Javascript

Margin in javascript is the same margin in html. You can set the amount of margin an element has using Javascript. To be clear, margin is the space between the border and the outside container holding the element. 1. How to set margin in Javascript You can change the margin... Read more

.map() method in javascript- Beginner guide

I ran into a challenge that required use of  .map(), .reduce() and .filter() methods. Previously, I have been tiptoeing around ES6 syntax. Why you ask? I found it a bit tough for me to understand. I am going to share with you some of the things I learnt in this... Read more

How To Change Padding Using Javascript

In this guide, you’ll learn how to change padding dynamically using Javascript, with a focus on an interactive button. There are two ways you can go about doing this. 1: Using JavaScript Only For beginners, the most straightforward way to dynamically adjust padding is by employing JavaScript directly. When a... Read more