Javascript | Popular terms on the website

A complete description of the article to inform more clearly and clearly is a mandatory requirement. We have thought about how Nickgenom users will find the most useful information.

| English | | Filipino | | Indonesia | | Malay | | Thai | | Vietnamese |
0 times seen

Javascript | Popular terms on the website

published on : 15 September 2020

In the early days when I was just starting to get to know the website and trying to learn to create a website, I found this javascript code to be creepy. It occurred to me that I should stay away from this code as much as possible. Javascript at that time looked like a formula full of strange foreign symbols.

Over time, it turns out that this code can play a big role in the beauty of a website, such as providing animation effects, sort order, notification settings, and so on.

If you were like me back then, scared to learn but didn't know where to start. This article will take you to get acquainted with javascript and help you find encouragement and enthusiasm to get to know this javascript code in more depth. Although not much but I hope it will be useful to you. We'll start with the most frequently used terms in javascript.

In fact, there are many types of terms in javascript. But we will concentrate on building a soul liking javascript on this page. So, after you have read this article, it is highly recommended to look for other sources to perfect your knowledge of javascript.

Var

Var is the most common way to create variables in JavaScript. The var statement declares a variable. Variables are containers for storing information. Creating variables in JavaScript is called "declaring" a variable:

  • var myCat = "puppus";

String

JavaScript strings store a string of characters such as "John Doe". Strings are text. They are denoted by the surrounding text with single or double quotes. Example:

  • "string of text"
    'string of text'
    //
    string1 + string2
    //
    'some' + 'text'; // returns 'sometext'
    const first = 'my';
    const second = 'string';
    const union = first + second; // union variable is the string 'mystring'

Array

Arrays are objects that store multiple values in one variable:

  • var cars = ["Saab", "Volvo", "BMW"];
    //
    var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37];
    primes[0]; // 2
    primes[3]; // 7
    primes[150]; // undefined
    //
    var arr = ["js", 2, true];
    arr[0]; // "js"
    arr[1]; // 2
    arr[2]; // true

Arrays can be created in 3 ways;

  • 1. Literal
    const arrayName = [element0, element1, ..., elementN]
    const primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37];
  • 2. Multi-Dimensi
    // Two dimensions, 3x3
    const multidimensionalArray = [[1,2,3],[4,5,6],[7,8,9]]
  • 3. Constructor
    const stuff = new Array();

    stuff[0] = 34;
    stuff[4] = 20;

    stuff;
    // [34, undefined, undefined, undefined, 20]

    const myArray = new Array(45 , 'Hello World!' , true , 3.2 , undefined);
    console.log(myArray);

    // output: [ 45, 'Hello World!', true, 3.2, undefined ]

Function

JavaScript functions are collections of code designed to perform a specific task. This allows us to define our own functions in JavaScript. It can perform tasks or calculate grades. It's like a reusable snippet of code. Imagine, having 20 loops, and then having one function to handle all of them. To use a function, you have to define it somewhere in the scope where you want to call it. A function definition (also called a function declaration) consists of the function keyword, followed by the function name, a list of function arguments, enclosed in brackets and separated by commas, a JavaScript statement that defines the function, enclosed in curly braces {}.

  • function myFunction(p1, p2) {
    return p1 * p2; // The function returns the product of p1 and p2
    }

Comments

Comments in javascript are used to improve code readability. This comment was not executed. It has its own function as notes, suggestions, warnings, etc. This can be described as if you had written 100 lines of code and then forgot the function of each line of javascript code that you wrote earlier, then this comment will help remind you.

  • console.log('This code will be run');
    // console.log('Because this line is in a comment, this code will not be run.')
    // This is a single line comment.

Console

This console code is used for debugging, which will print text messages to the console. For example, you want to display the message "I am debugging", then you open the browser console with an inspect element, and you will see the message in the console inspect element tab.

  • const name = 'I'm debugging';
    console.log(name);

If

The if code in javascript will say that if this condition is true, do this, or do something else or nothing. It takes many forms. Example:

  • if (animal == 'dog') {
    console.log('Bark, bark!');
    } else {
    console.log('Meow!');
    }

The code above reads like this: "If a dog is found, then say / write it on the Bark console, bark !, or if not, then say / write it on the Meow console!"

== VS ===

In javascript, you will often see an equal sign written twice side by side (==), this says only do value checking (no type checking).

Whereas if you meet an equal sign which is written twice together (===), this says do value checking and type checking.

  • '1' == 1 // true (same value)
    '1' === 1 // false (not the same type)

    true == 1 // true (because 1 evaluates as truthy, though it's not the same type)
    true === 1 // false (not the same type)

Loops

Loop functions are looping actions. It will perform a loop action or the same action multiple times in a line.

  • var i;
    for (i = 0; i text += cars[i] + "<br>";
    }

The code above will loop for this:

  • text += cars[0] + "<br>" ;
    text += cars[1] + "<br>" ;
    text += cars[2] + "<br>" ;
    text += cars[3] + "<br>" ;
    text += cars[4] + "<br>" ;
    text += cars[5] + "<br>" ;

Objek

Objects represent the <object > element in HTML. Objects are the basic data structures in JavaScript. Objects have properties, also known as keys, that are assigned a value.

What can you do with this object function?

  • 1. access the <object> element by using "getElementById ()";
  • 2. create an <object> element by using the method "document.createElement ()";
  • // using getElementById ()
    var x = document.getElementById("myObject");

    // using document.createElement ()
    var x = document.createElement("myObject");

    // or describe a property, such as:
    var obj = {
    name: 'Bob',
    married: true,
    'mother\'s name': 'Alice',
    'year of birth': 1987,
    getAge: function () {
    return 2012 - obj['year of birth'];
    },
    1: 'one'
    };

These are some of the terms that I can present on this page. To dig deeper into javascript, you can use an external free reference which I also used as a reference for creating this page:

Tags:

Comment