My-Introduction-To-JavaScript

Adeniye Kehinde Afusat
3 min readMar 14, 2021

JavaScript for me is a langauge that has a large syntax and also has a way of writing it.

I realized JavaScript has a very similar datatype to Python which data types also include boolean, strings, null value, undefined, symbol, object.

Now I am getting used to learning JavaScript function like

#Alert, Console.log, confirm, prompt,

What I find amazing using JavaScript is the magic of using the same language with other languages like HTML and CSS.

Example of this is using JavaScript HTML methods: getElementById()

<!DOCTYPE html>
<html>
<body>
<h2> My name is Adeniye Kehinde</h2><p id="demo">I am a technology enthusiast who loves to code.</p><button type="button" onclick='document.getElementById("demo").innerHTML = "Gotcha!"'>want to know more!</button></body>
</html>
Output of using the JavaScript Html methods: getElementById()

Variables can be declared using:

  • let
  • const (constant, can’t be changed)
  • var

Variables defined with const behave like let variables, except they cannot be reassigned:

It took me a while before I could understand the word “ Scope” in JavaScript.

The scope is a policy that manages the accessibility of variables. To simplify this, I will try to declare a variable using const

const word = 'Hello';
console.log(word);

Output: 'Hello'

This variable can be log in the next line after the declaration. But when declared outside the scope the variable becomes inaccessible. e.g

if (true) {
const word = 'Hello';
}
console.log(word); // ReferenceError: message is not defined

console.log (word ) through an error because the if code block creates a scope for word variable. And word variable can be accessed only within this scope. i.e {}.

The blockscope variables includes const and letbut doesn’t includevar

if (true) {
// "if" block scope
var count = 0;
console.log(count); // 0
}
console.log(count); // 0

Even when second console.log(count)isn’t within the scope{}, it still displayed it output without throwing an error.

A variable declared inside the global scope is named global variable. Global variables are accessible from any scope.

<script src="myScript.js"></script>// myScript.js

// "global" scope
let counter = 1;

Looking forward to continuing learning JavaScript Fundamentals.

--

--

Adeniye Kehinde Afusat

Kehinde is a technology enthusiast, experienced with Azure DevOps. She has expertise in Cloud technologies and software programming.