search
HomeWeb Front-endJS TutorialJavaScript is really not difficult - review the basics_Basics

Foreword
Before talking about Jquery, let’s first learn the basic knowledge issues in Javascript (hereinafter referred to as JS) language. At that time, the basic knowledge was similar for each programming language. For variables, , functions, conditional statement blocks, loop statement blocks, etc. The writing method is different for each language. For example, when defining variables in JS, you have to use var to declare the local variable, and for weak For the type language JS, you can also not add var, but if you don't add it, the variable will be considered a global variable. This should be noted.

Variable
The value can change during the running of the program (haha, the definition in the book more than 10 years ago)
var people; //Declare a name Variable for people
var people="good boy"; //Assign a value to the variable when declaring it. The browser automatically interprets it as a character variable
var age=23; //Declare a local variable, type For integer
age=30; //Declare a global variable of type integer. During program execution, it will not be released

Function
In order to implement a Function organizes some code blocks together to form a whole. We call it function. It can greatly reduce the amount of code duplication and make the program clearer
Copy the code The code is as follows:

// Standard writing
funciton helloFun(){
alert("hellow world")
}
//How to write variable form
var helloFun=function(){
alert("hellow world")
}
// Function can have parameters, it is a weak type
var helloFun=function(msg){
alert(msg);
}
// Function call
helloFun("hello world");

Conditional statement
For one thing, there are multiple results. At this time, conditional statement appears. If the condition fixes several values, you can use switch, otherwise use if...else, see the code
Copy code The code is as follows:

// switch instance
var inputNumber=document.getElementByID( "type");
switch(inputNumber)
{
case 1:
alert("Type 1");
break;
case 2:
alert( "Type No. 2");
break;
case 3:
alert("Type No. 3");
break;
default:
alert("throw new Exception( )");
break;
}
// if instance
var inputAge=document.getElementByID("age");
if(inputAge>1 && inputAge{
alert("Underage");
}
else if (inputAge>=18 && inputAge{
alert("Adult");
}
else if(inputAge>=70)
{
alert("elderly")
}
else
{
alert("There is an error in filling out the form") ;
}

Loop statement
means to repeatedly execute a code block when a certain condition is followed. We can use while, for, etc.
Copy code The code is as follows:

// for loop
var arr=[1 ,2,3]
for(int i=0;j=Arr.length;iconsole.log(arr[i]); // The Firefox console can see Result
}

In fact, in the JS world, the execution performance of the code is also very particular. The performance of the way we write the for statement is not wrong, but if it is written as follows, the performance There will be a decrease, because every time it traverses
, it will find the length of Arr.
Copy code The code is as follows:

// for loop
var arr=[1 ,2,3]
for(int i=0;iconsole.log(arr[i]); // Poor performance
}

Okay, that’s it for writing the basic knowledge of JS programming. From next time, I will introduce the relevant knowledge of jquery. Thank you for reading!
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
内部错误:无法创建临时目录 [已解决]内部错误:无法创建临时目录 [已解决]Apr 17, 2023 pm 03:04 PM

Windows系统允许用户使用可执行/设置文件在您的系统上安装各种类型的应用程序。最近,许多Windows用户开始抱怨他们收到一个名为INTERNALERROR:cannotcreatetemporarydirectory在他们的系统上尝试使用可执行文件安装任何应用程序的错误。问题不仅限于此,而且还阻止用户启动任何现有的应用程序,这些应用程序也安装在Windows系统上。下面列出了一些可能的原因。运行可执行文件进行安装时不授予管理员权限。为TMP变量提供了无效或不同的路径。损坏的系

PHP是如何存储变量的?zval结构体你了解吗?PHP是如何存储变量的?zval结构体你了解吗?May 26, 2022 am 09:47 AM

在 PHP 中定义一个变量是不需要声明类型的,一开始给变量 $a 赋予一个整型值,后面又可以轻而易举地将其改变为其他类型。那在 PHP 的源码中是如何来存储这个变量 $a 的呢?带着这个疑问我们一起去看一看 PHP 的源码。

Go语言的变量有几种类型Go语言的变量有几种类型Jan 10, 2023 am 11:34 AM

变量有三个类型:1、函数内定义的变量称为局部变量,其作用域仅限于函数内部;局部变量不是一直存在的,它只在定义它的函数被调用后存在,函数调用结束后这个局部变量就会被销毁。2、函数外定义的变量称为全局变量,其只需要在一个源文件中定义,就可以在所有源文件中使用;全局变量声明必须以var关键字开头,如果想要在外部包中使用全局变量的首字母必须大写。3、函数定义中的变量称为形式参数。

从头学习:掌握Go语言的基础知识从头学习:掌握Go语言的基础知识Feb 01, 2024 am 08:45 AM

从零开始:学习Go语言的基础知识简介Go语言,又称Golang,是一种由Google开发的开源编程语言。它于2009年发布,并迅速成为一种流行的语言,尤其是在Web开发、分布式系统和云计算等领域。Go语言以其简洁、高效、并发性强等特点而著称。基本语法1.变量和常量在Go语言中,变量和常量都是类型化的。变量可以存储数据,而常量则不能改变。变量的声明格式为:v

学习MySQL必看!详细讲解SQL语句基础知识学习MySQL必看!详细讲解SQL语句基础知识Jun 15, 2023 pm 09:00 PM

MySQL是一个开源的关系型数据库管理系统,被广泛地应用于Web应用程序的开发和数据存储。学习MySQL的SQL语言对于数据管理员和开发者来说是非常必要的。SQL语言是MySQL中的核心部分,因此在学习MySQL之前,你需要对SQL语言有充分的了解,本文旨在为你详细讲解SQL语句基础知识,让你一步步了解SQL语句。SQL是结构化查询语言的简称,用于在关系型数

PHP Notice: Undefined variable解决方法PHP Notice: Undefined variable解决方法Jun 25, 2023 pm 01:00 PM

如果您是PHP开发者,您可能会时不时遇到“PHPNotice:Undefinedvariable”错误。这种错误是由于您尝试使用未定义的变量而引起的,它会在PHP代码中以警告的形式显示。虽然它通常不会导致应用程序崩溃,但影响程序的完整性和可靠性。在本篇文章中,我们将探讨此类PHP错误,并提供一些解决方法,帮助您避免此类错误。什么是“Undefined

学习canvas,需要了解哪些基本概念?学习canvas,需要了解哪些基本概念?Jan 17, 2024 am 10:37 AM

学习canvas需要掌握哪些基础知识?随着现代Web技术的发展,使用HTML5中的标签进行绘图成为一种常见的方式。Canvas是一种用于绘制图形、动画和其他图像的HTML元素,它可以利用JavaScript进行操作和控制。如果你想要学习canvas并掌握其基础知识,下面将为你详细介绍。HTML和CSS基础知识:在学习canvas之

Go语言编程入门指南:基础知识与实际应用速成Go语言编程入门指南:基础知识与实际应用速成Jan 23, 2024 am 09:31 AM

快速入门Go语言编程:基础知识与实践指南Go语言作为一门新兴的编程语言,因其简洁、高效和并发性而备受开发者的青睐。无论你是初学者还是有一定编程经验的开发者,本文将带你快速入门Go语言编程,并提供一些实践指南和具体代码示例。一、安装Go语言环境要开始使用Go语言进行编程,首先需要在你的计算机上安装Go语言环境。你可以从Go官方网站(https://golang

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.