Breaking

domingo, 6 de febrero de 2022

relevant javascript codes








 Comments

You can write comments between JavaScript code, just like you can in CSS. The browser ignores text marked as a comment. In JavaScript, single-line comments are written like this:


// This is a comment

Copy to Clipboard

But you can also write comments on more than one line, just like in CSS:


/*

this is a comment

of several lines.

*/


conditionals

Conditionals are code structures that allow you to test whether an expression returns true or not, and then execute different code depending on the result. The most common form of conditional is the if...else call. So for example:


let ice cream = 'chocolate';

if (ice cream === 'chocolate') {

  alert('Yes, I love chocolate ice cream!');

} else {

  alert('Awwww, but my favorite is the chocolate one...');

}


The expression inside if (... ) is the criteria — it uses the identity operator (described above) to compare the variable ice cream with the string chocolate to see if the two are equal. If this comparison returns true, the first block of code is executed. If not, that code is skipped and the second block of code after the else statement is executed.


Functions

Functions are a way to encapsulate functionality that you want to reuse, so that you can call that function with a single name, and you don't have to write the entire code each time you use it. You have already seen some functions above, for example:


let VariableName = document.querySelector('h1');

Copy to Clipboard

alert('Hello!');


These document.querySelector and alert functions are built into the browser so you can use them at any time.


If you see something that looks like a variable name, but has parentheses —()— at the end, it's probably a function. Functions often take arguments—bits of data that they need to do their job. These are placed inside the parentheses, separated by commas if there is more than one.


For example, the alert() function makes a popup appear inside the browser window, but you need to give it a string as an argument to tell it what message to write to the popup.


The good news is that we can define our own functions—in the following example we write a simple function that takes two numbers as arguments and multiplies them together:


function multiply(num1,num2) {

  let result = num1 * num2;

  return result;

}


events

To create real interaction on your website, you must use events. These are code structures that capture what is happening in the browser, and allow code to be executed in response to the actions that take place. The most obvious example is a click (click event), which is triggered by clicking on something. To demonstrate this, try entering the following into your console, then clicking on the current page:


document.querySelector('html').onclick = function() {

    alert('Ouch! Stop poking me!');

}

Copy to Clipboard

There are many ways to bind an event to an element; here we have selected the <html> element and assigned to its onclick property an anonymous function (unnamed function) that contains the code that will be executed when the event happens.


Note that


document.querySelector('html').onclick = function(){};

Copy to Clipboard

It is equivalent to


let myHTML = document.querySelector('html');

myHTML.onclick = function(){};

Copy to Clipboard

it's just a shorter way of writing it.


hosting web


hosting linux


web hosting  


free hosting


cheap hosting


vps 


No hay comentarios:

Publicar un comentario