js的自学疑惑
关于自学js的疑惑js学了快有一个多月了,但是总感觉没什么提升,是什么原因呢?
window.alert("我的javaScript");document.write(Date());
var a = 1;
var b = "str";
console.log(typeof a);
console.log(typeof b);
var x = 1;
x = String(x);
console.log(typeof x);
var x = "";
var i = 0;
cars = ["aodi","benchi","baoma","bentian"];
do {
x = x + "值" + i + "<br>" +cars;
i++
}while(i <= 4);
document.write("你好" + x);
result = 1 > 2;
console.log(result);
console.log("\u2620");
var a = 1;
var b = 2;
var c = 3;
max = a > b ? a > c ? a : c : b > c ? b : c;
console.log(max);
for (i = 0; i < 3; i++) {
var x = 1;
if (true) {
alert(x);
}
}
var scorev = prompt("sss");
alert(scorev);
var str = prompt("nihao");
alert(scorev);
var ssr = "q";
prompt("q");
alert(ssr);
alert("1");
var x = 99;
switch(true) {
case x <= 10 :
console.log("10");
break;
default :
console.log("不执行");
break;
}
var x = 0;
while (true) {
alert(x++);
if (x == 10) {
break;
}
}
var money = 1000;
var count = 0;
while (money < 5000) {
money*=1.2;
count++;
console.log(count);
}
var num = prompt("请输入一个质数");
if (num > 1) {
var flag = true;
for (var i = 2; i < num; i++) {
if (num % i == 0) {
flag = false;
}
}
if (flag) {
alert("是");
}else {
alert("不是");
}
}else {
alert("非法值");
}
for (var i = 5; i > 0; i--) {
for (var j = 0; j < i; j++ ) {
document.write("*");
}
document.write("<br />");
}
for (var i = 0; i < 5; i++) {
for (var j = 0; j < i+1; j++) {
document.write("*");
}
document.write("<br />");
}
for (var i = 0; i < 5; i++) {
for (var j = 0; j < 5 - i; j++) {
document.write("*");
}
document.write("<br />");
}
for (var i = 1; i <= 9; i++) {
for (var j = 1; j <= i; j++) {
document.write("<span>" + j + "*" + i + "=" + j*i + "</span>");
}
document.write("<br />");
}
for (var i = 2; i <=100; i++) {
var flag = true;
for (var j = 2; j < i; j++) {
if (i % j == 0) {
var flag = false;
}
}
if (flag) {
document.write(i + "<br>");
}
}
for (var x = 2; x <= 100; x++) {
var i = 2;
if (x % i == 0){
document.write(x);
}
}
for (var x = 2; x <= 100; x++) {
var flag = true;
var i = 2;
if (x % i !== 0){
var flag = false;
}
if (flag) {
document.write(x + "<br />");
}
}
if (1) {
document.write("你好嘎嘎嘎")
}
for (var i = 0; i < 5; i++) {
console.log("外层循环" +i);
for (var j = 0; j < 5; j++) {
console.log("内层循环" + j);
}
}
console.time("test")
for (var i = 0; i < 5; i++) {
label: for (var j = 5; j <= 5; j++) {
console.log(j);
break label;
}
}
console.timeEnd("test")
console.time("test");
for (var i = 2; i <= 1000; i++) {
var flag = true;
for (var j = 2; j <= i; j++) {
if (i%j == 0) {
flag = false;
//break;
}
}
if (flag) {
console.log(i);
}
}
console.timeEnd("test");
result = console.log(Math.sqrt(9));
var obj = new Object();
obj.name = "你好";
var obj2 = obj;
console.log(obj2.name);
var obj = new Object();
var obj1 = new Object();
obj.name = "mn";
obj1.name = "mn";
console.log(obj == obj1);
var obj = {
name:"孙悟空",
age:500,
test:{lw:liuwei,age:17}
};
console.log(obj.test);
var fun = new Function();
function myFunction() {
}
var myFunction = function(){
}
function fun(a,b,c){
var d = a + b + c;
return d;
}
var result = fun(1,2,3);
console.log(result);
function isOu(num){
return num % 2 == 0;
}
result = isOu(50);
console.log(result);
function mianji(r){
return 3.14*r*r;
}
result = mianji(5);
console.log(result);
function fun(o){
console.log(o.name,o.age,o.gender);
}
var obj = {
name:"孙悟空",
age:"18",
gender:"男"
}
fun(obj);
function mianji(r){
return 3.14*r*r;
}
var result = mianji(100);
console.log(mianji);
(function(a,b){
console.log(a);
console.log(b);
})(1,2);
var obj = new Object();
obj.name = "孙悟空";
obj.age = 18;
obj.sayname = function(){
console.log(obj.name);
}
obj.sayname();
// console.log(obj.saynme);
var obj = {
name:"liuwei",
firstname:"wei",
lastname:"liu"
}
for (var n in obj){
console.log(n);
console.log(obj);
}
var a = 0;
console.log(window.a);
console.log(a);
var a = 123;
function myFunction(){
var a = 888;
console.log(a);
}
myFunction();
var myFunction1 = function(){
var b = 999;
console.log(b);
}
myFunction1();
function createPerson(fname,age,gender){
var obj = new Object();
obj.fname = fname;
obj.age = age;
obj.gender = gender;
obj.sayName = fun;
obj.sayName = function(){
alert(this.fname);
}
return obj;
}
var obj1 = createPerson("李",18,"男");
var obj2 = createPerson("啊",12,"男");
console.log(obj1);
function My(){
alert(this);
}
var fun = new My();
console.log(fun);
function club(){
}
function tab(){
}
console.log(club.prototype);
console.log(tab.prototype);
function Function(name,age,gender){
var obj = new Object();
obj.name = name;
obj.age = age;
obj.gender = gender;
obj.sayName = function(){
alert("嘿嘿");
}
return obj;
var obj1 = ("liuwei",18,"女");
console.log(obj1);
}
function MyClass(){
}
MyClass.prototype.name = "我是原型中的名字";
var mc = new MyClass();
mc.age = 18;
console.log(mc.name);
var obj = new Object();
obj.name = "你好";
console.log(obj.name);
function person(name,age,gender){
this.name =name;
this.age = age;
this.gender = this.gender;
}
var per = new person("孙悟空","18","男");
result = per.toString();
console.log(per.__proto__.__proto__.hasOwnProperty("toString"));
per.toString = function(){
return "我是菜鸟";
}
var result = per.toString();
console.log(result);
var arr = new Array();
arr = 1;
arr = 2;
arr = 200;
console.log(arr);
var arr = ;
console.log(arr);
var arr = [,,];
console.log(arr);
var arr = ["s","z","s",];
result = arr.push("g","h","k");
console.log(arr);
console.log(result);
arr.unshift("你好","呵呵","大白");
arr.shift();
arr.shift();
console.log(arr);
var arr = ["q","w","e","r","t","y","u","i","o","p"]
for(var i = 0; i < arr.length; i++){
console.log(arr);
}
var per = new person("你好","我是","小白");
console.log(per);
感觉写的很混乱{:1_937:} 做几个东西就知道该怎么写了。
比如说写个油猴插件。。。。
多看看别人写的代码
你这代码说实在的,一点看下去的欲望都没有。{:301_1008:} 你怎么学的,一个月不能就学些1+1吧 阁下看的是李立超老师的教程吧 老是写这些入门级别的代码怎么能提升呢,编程语言厉害的地方是将编程语言运用到其他地方,如果你学完基础语法,建议你学学项目什么的,当你做项目发现没什么提升的时候再学学数据结构与算法深造 多写注释。养成好习惯。 js二十五天,表示只有项目才能提高,实践多敲很重要 光学没用,要项目中遇到以后才能加深印象 可以尝试去看一下axios库,感受一下,代码也不多 楚子沦i 发表于 2021-11-19 20:33
做几个东西就知道该怎么写了。
比如说写个油猴插件。。。。
多看看别人写的代码
就是要写项目 对吧 写的多了 就知道怎么写了
页:
[1]
2